Hello, welcome to therichpost.com. In this post, I will tell you Change Product Order Status Woocommerce Hook. WordPress is the best cms and Woocommerce is the best Ecommerce plugin. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress. Now I am going to tell you how the hooks work.
I am using Change Woocommerce Thankyou Hook to Change Product Order Status.
Here is the working and testing code for Change Product Order Status Woocommerce Hook and you need to add this into your theme’s functions.php file:
add_action( ‘woocommerce_thankyou’, ‘Change_Product_Order_Status’, 10, 1 );
function Change_Product_Order_Status( $order_id ) {
if ( ! $order_id )
return;
$order = wc_get_order( $order_id );
// Updating order status to processing for orders delivered with Cheque.if ( get_post_meta($order->id, ‘_payment_method’, true) == ‘cheque’ )
$order->update_status( ‘processing’ );
}
There are so many hooks in wordpress and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com
Same like WooCommerce Order Status Control Good
yes it is 🙂
Hi, I need help to change/update the default On_Hold Status for BACS payment for Preorders only.
Not sure if the above coding can be tweaked to get it done? I tried the following but it doesn’t work.
// ———————
// 3. Update Status from On_Hold to Preorder_Pending
add_action( ‘woocommerce_thankyou’, ‘woocommerce_thankyou_change_order_status’, 10, 1 );
function woocommerce_thankyou_change_order_status( $order_id ){
if( ! $order_id ) return;
$order = wc_get_order( $order_id );
// Status without the “wc-” prefix – Change from On Hold to Preorder Pending
if ( is_product_category( ‘Preorders’ ) ) {
if( $order->get_status() == ‘On Hold’ );
$order->update_status( ‘Preorder Pending’ );
} else {
$order->update_status( ‘On Hold’ );
}
If I fully use your coding as per below : Maybe I can change accordingly, but please confirm if it will work.
add_action( ‘woocommerce_thankyou’, ‘Change_Product_Order_Status’, 10, 1 );
function Change_Product_Order_Status( $order_id ) {
if ( ! $order_id )
return;
$order = wc_get_order( $order_id );
// Updating order status to Preorder Pending for orders with Product Category / Stock Status = Preorder.
if ( get_post_meta($order->id, ‘is_product_category, true) == ‘Preorders’ )
$order->update_status( ‘Preorder Pending’ );
}
Maybe something is not right in my code earlier too.
Please advise!
Thanks.
Please check this line:
if ( get_post_meta($order->id, ‘is_product_category, true) == ‘Preorders’ )
to
if ( get_post_meta($order->id, ‘is_product_category’, true) == ‘Preorders’ )
Thank you
Hi Ajay,
Let me rephrase my reply.
New Coding I tried as per your advise :
add_action( ‘woocommerce_thankyou’, ‘Change_Product_Order_Status’, 10, 1 );
function Change_Product_Order_Status( $order_id ) {
if ( ! $order_id )
return;
$order = wc_get_order( $order_id );
// Updating order status to Preorder Pending for orders with Product Category / Stock Status = Preorder.
if ( get_post_meta($order->id, ‘is_product_category’, true) == ‘Preorders’ )
$order->update_status(‘Preorder_Pending’);
};
But the OUTCOME is still not able to achieve. It is still using the Default On-hold status for BACS, it doesn’t change to Preorder Pending Status automatically for the Preorders Category
🙁
Hi Ajay,
Thank you for your reply.
I have changed it accordingly. This is the new code :
add_action( ‘woocommerce_thankyou’, ‘Change_Product_Order_Status’, 10, 1 );
function Change_Product_Order_Status( $order_id ) {
if ( ! $order_id )
return;
$order = wc_get_order( $order_id );
// Updating order status to Preorder Pending for orders with Product Category / Stock Status = Preorder.
if ( get_post_meta($order->id, ‘is_product_category’, true) == ‘Preorders’ );
$order->update_status(‘Preorder_Pending’);
};
Let me try and activate it.
Thanks.
Great!!
Sorry Ajay, please see my new reply above… . the OUTCOME is not achieved….
I need to have the Order status changed to Preorder Pending for these Preorders Category (which also has Stock status : Preorder).
Any other way to do the coding? Currently all will be paid through BACS.
I will check it with and update you. for more help email me on therichposts@gmail.com.
Sure, Will do so….. tight budget, otherwise would have gone for the paid plugins….