I am trying to trigger a function when an order is completed. I am using this code:
add_action('woocommerce_order_status_completed', array($this,
'payment_complete'
), 1);
and then this function:
public function payment_complete($order_id) {
$this->generate_order_file($order_id);
}
This function is meant to generate an order file, but it's not being called at all. I previously tried getting it to add a message to the error log,
I am using the WooCommerce Order Status Control plugin, and orders are automatically changing to complete upon payment. Yet for some reason the woocommerce_order_status_completed action isn't triggering.
The best way is using this action:
add_action( 'woocommerce_order_status_completed', 'your_function', 10, 1);
function your_function($order_id) {
}
FUNCTION
function payment_complete( $order_id, $old_status, $new_status ){
if( $new_status == "completed" ) {
$this->generate_order_file($order_id);
}
}
HOOK
add_action( 'woocommerce_order_status_changed', array( $this, 'payment_complete'), 99, 3 );
NOTE
Make sure that the hook is executed. Is yes, this will work.
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With