Sorry for the delay. Still waiting for the customer permission to clone the site.
At the same time, while I did some more tests, I have stumbled to a really strange behaviour.
This code doesn't work (the "wpcf-woo-status" value don't change):
Unfortunately i'm not sure what happens in this case.
However I've found a way to workaround this using the hook below.
function func_status_change($post_id) {
// If this is a revision, get real post ID
if ( get_post_type($post_id) == 'shop_order' )
$woo_order = wc_get_order( $post_id );
$woo_order_status = $woo_order->get_status();
if ( $woo_order_status == 'cancelled' || $woo_order_status == 'failed' ){
update_post_meta( $post_id, 'wpcf-custom-order-status' , $woo_order_status );
}
}
add_action( 'save_post', 'func_status_change' );
I've tested this and it works fine and updates the status once the status is either failed or cancelled.
Please let me know if this alternative helps.
Thanks,
Shane
Hi, thanks for the new code (please notice that he generate an error, and I had to add some missing {} )
Sadly, it doesn't solve my problem.
As my old code, it is properly fired, when the order status change, no question.
But it's the "update_post_meta" which is not working.
I simply cannot get the value saved on the Types custom field.
I'm not able to debug the "woocommerce_order_status_changed" hook. It would appear that in the sequence of hooks that fire after the woocommerce_order_status_changed hook is making some unknown changes and causing the custom field not to update.
As you can see when the die function is added it breaks the hook at the point of the die and doesn't allow any other function after the die to run.
The best thing I can advise you to do regarding this hook is to get in touch with the Woocommerce support team and to as them for assistance with the hook.
I can only debug Toolset based hooks. Doesn't the code I provided fit your scenario of updating the post meta field if the status is set to Cancelled or failed?
I think I have found the problem but not the solution.
The function works if inserted in the Toolset's settings "custom code", but not if inserted in my custom plugin.
Please notice that I have many other functions running without problem on my custom plugin.
And it doesn't work also if pasted in functions.php