Woocommerce order status changed action is not triggering

Hi,
I’m trying to update custom vendor attributes each time an order status changes, but, the action never triggers. Am I doing something wrong with “woocommerce_order_status_changed”?

The snippet is in a code snippet of the “Code Snippets” extension. It is active, but is entirely ignored. I try to trigger the action by completing orders via the “Complete Order” button on the “Order Details” page.
The function doesn’t throw any errors or messages. I even tried returning error messages at the top of the function, but nothing happened. I’m guessing the function is never triggered. I also checked this post of the forum for help.

The custom functions update the following custom vendor attributes:

  • Completed Commissions: Number of completed commissions from the vendor
  • Clients: List of Client IDs the Vendor successfully worked with

If there’s a better way to do this, please let me know.

add_action( 
	'woocommerce_order_status_changed', 
	function ($order_id, $old_status, $new_status, $order){
		// Check vendor.
		if ( ! $order->get_meta( 'hp_vendor' ) ) {
			return;
		}

		chuwu_update_vendor_completed_commissions( $order->get_meta( 'hp_vendor' ) );
		chuwu_update_vendor_clients( $order->get_meta( 'hp_vendor' ) );
		return;
	}, 
	1000, 
	2
);

Thank you!

Please change number 2 at the end of your code snippet on number 4 as this number is responsible for a number of parameters that you set in the function and this function has four parameters

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.