[SOLVED] How to get the order id that the customer canceled with the hook


This Content is from Stack Overflow. Question asked by Steve

I have another API inside plugin for making another order in a website so I want when the customer cancel the woocommerce order I’ve to canel also the other website order, I’ll have the order id of woocommerce and the order id of the other website in wp_post_meta

I just want to know how to get the order id that customer canceled to call the order id and the other one to cancel both

function cancel_SP_order(){

// how to get the order id cancelation with the hook 
get_post_meta() ..... // for example 

// I get $order_id from wp_post_meta which has the other order id 

// I cancel the other 


if there’s a better way for sure I welcome


Luckily for you, the hook itself passes the $order_id.You can access it like this:

function cancel_SP_order( $order_id ){

// I get $order_id passed by the hook to use directly.

// I cancel the other 

add_action('woocommerce_cancelled_order','cancel_SP_order', 10, 1);

The first parameter after your function name (’10’) is the priority in which your function will run. The second one, ‘1’, is the number of parameters passed from the hook to the function. In this case it is just ‘1’, the order ID that you need.

Let me know if you need more help?

This Question was asked in StackOverflow by Steve and Answered by Tami It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?