12

I am looking for a hook which will be triggered after someone submit checkout form and order placed ( no matter he made the payment or not ) .

I tried woocommerce_new_order

But it's not working.

3
  • Post your code that's not working. Dec 19, 2015 at 19:31
  • function action_woocommerce_new_order( $order_id ) { update_option('new_order', $order_id ); }; add_action( 'woocommerce_payment_complete', 'action_woocommerce_new_order', 10, 1 );
    – Iftieaq
    Dec 19, 2015 at 19:47
  • 'woocommerce_new_order' hook is the answer. Mar 4, 2020 at 22:09

2 Answers 2

14

Try woocommerce_thankyou hook. This will trigger after recieving order successfully, no matter how user made payment.

$hook_to = 'woocommerce_thankyou';
$what_to_hook = 'wl8OrderPlacedTriggerSomething';
$prioriy = 111;
$num_of_arg = 1;    
add_action($hook_to, $what_to_hook, $prioriy, $num_of_arg);

function wl8OrderPlacedTriggerSomething($order_id){
      //do something...
}

For more reference dig into woocommerce/templates/checkout/thankyou.php

3
  • 6
    Note: this event will be triggered again if the end user refreshes the thank you page for whatever reason. Dec 23, 2017 at 12:27
  • 2
    Is there a hook that only works on save?
    – benedict_w
    Oct 24, 2018 at 12:59
  • 2
    also note this hook will not be triggered if a user somehow skips the thankyou page
    – Yair Levy
    Feb 16, 2020 at 16:06
3

I found the solution. An old order already exists in my order list. So when I am adding new items in order, woocommerce just updating my old unpaid order. So I use woocommerce_resume_order action too. Now it's fine.

Not the answer you're looking for? Browse other questions tagged or ask your own question.