hooks – WooCommerce thank_you action on order created via REST API


I have the following line of code that triggers after checkout and when the user is on thank you page.

add_action('woocommerce_thankyou', 'cc_new_order');
function cc_new_order($order_id)
    // make an API call to an external app

The above code is not being triggered when I am creating an order via the WC Rest API. Here’s the code for making API call via the WooCommerce PHP client

// call wc api to create order
$order = $woocommerce->post('orders', $data);

$data is the example given in the WooCommerce REST API docs. I can see the new order from the WooCommerce admin dashboard, but the external API call triggered in the hook not is working. The hook (and the external API call) only works when an order is placed via UI.

Is there something that can be done? Maybe another hook that triggers after order placement but also via API in addition to UI way?

Vaibhav Rathore 2 weeks 2021-11-16T08:20:32-05:00 0 Answers 0 views 0

Leave an answer