I am making a WordPress plugin, where I need to make an API call every time order status updates to "processing" from "pending".
function __construct(){
add_action( 'woocommerce_after_order_object_save', [$this,'action_woocommerce_doba_order_import'], 10, 1 );
}
public function action_woocommerce_doba_order_import($order){
if ( 'processing' === $order->get_status() ) {
"API call here"
}
}
This code works fine when order status updates to "processing" from "pending" but it makes two additional API calls when status changes to something else from "processing".
So I get two additional API calls for each order it status changes from processing to something else.
I am definitely making some mistakes. Maybe I am using the wrong hook or need to put a different condition.
2
Answers
We have created a WordPress code for changing the order status, Hooks function call every time order status updates to "processing" from "pending".
You try this:
I tried to find this action in the newest version of the WooCommerce plugin [6.3.1] and I couldn’t, but I found out that there’s probably a better hook to use, which includes the new status.
So you could use it like this: