Woocommerce Hooks

Change Product Order Status Woocommerce Hook

How to add download pdf link in woocommerce single product page?

Change Product Order Status Woocommerce Hook

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

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

10 Comments

  • 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.