I try to create my custom payment gateway for woocommerce , but i have small problem in the cancelation process when i call the cancel api for the gateway i use action hook to call my cancelation function
add_action( 'woocommerce_order_status_changed','woo_order_status_change_custom' , 10, 3);
public function woo_order_status_change_custom($order_id, $old_status, $new_status ){
// custom api code
}
and its working fine when i cancel the order from the wp-admin, but when the customer try to cancel his order from his account page the hook not trigger the function .
Please any one could help with it ??
My Answer:
When a customer cancels an order from their account page, the order status is not changed in the same way as when an admin cancels it from the wp-admin. In this case, you can use a different hook to trigger your custom cancelation function.
You can use the 'woocommerce_order_status_cancelled' hook to trigger your custom cancelation function when a customer cancels an order from their account page. Here's how you can modify your code:
php
add_action( 'woocommerce_order_status_cancelled', 'woo_order_status_cancel_custom', 10, 1);
function woo_order_status_cancel_custom( $order_id ) {
// custom cancelation code
}
By using the 'woocommerce_order_status_cancelled' hook, your custom cancelation function will be triggered when a customer cancels an order from their account page. This should solve the issue you are facing with the cancelation process.
Rate this post
5 of 5 based on 2266 votesComments