skip to Main Content

I am writing a PHP script and need to retrieve an order id. My question is, at what point is the order created and when could I edit it? Thank you in advance for your answer.

2

Answers


  1. There are many hooks that allow update order to create a new order

    few are :

    add_action('woocommerce_thankyou', 'woocommerce_new_order', 10, 1);
    add_action( 'woocommerce_payment_complete', 'woocommerce_new_order', 10, 1 );
    

    You can use one of them(not both at a time)

    Full Example:

    add_action('woocommerce_thankyou', 'woocommerce_new_order', 10, 1);
    
    function woocommerce_new_order($order_id){
        //update_option('new_order', $order_id );
        $order = wc_get_order($order_id);
    }
    

    Here you got order_id and order(full order info).
    Now you can add/update/delete anything accordingly.

    Login or Signup to reply.
  2. If you want to update the order late or at any time just pass order_id(eg.115) and perform the operation accordingly

    add_action('init',function(){
      $order_id = 115;
      if($order_id){
        $order = new WC_Order($order_id);
        $order->update_status('wc-processing'); 
      }
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search