0

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.

Gandalf69
  • 65
  • 8

2 Answers2

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'); 
  }
});
Rajeev Singh
  • 1,724
  • 1
  • 6
  • 23
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.

Rajeev Singh
  • 1,724
  • 1
  • 6
  • 23
  • What to do when I want to only add/change something to existing order (Woocommerce create order and i want to edit this later)? – Gandalf69 Aug 12 '21 at 11:09