Reputation: 1
I am trying to include a function after an order is updated (admin side), but it doesn´t work. I want to call a function when someone update an order (order status, etc...). I am trying this:
add_action( 'woocommerce_process_shop_order_meta', 'woocommerce_process_shop_order', 1, 1);
function woocommerce_process_shop_order () {
// Code
}
Ive been trying to redirect to other web with header("Location: www.example.com")
, but the page doesn´t redirect when an order is update :(
Please, can you help me to solve it?
Thanks!
Upvotes: 0
Views: 365
Reputation: 5261
There you go. Tested and works. Goes into functions.php
file of your child theme:
add_action( 'post_updated', 'post_updated_action', 20, 3 );
function post_updated_action( int $post_id, WP_Post $post_after, WP_Post $post_before ): void {
// To be sure it gets called when updated from the admin dashboard and is order
if ( $post_before->post_type !== 'shop_order' || ! is_admin() ) {
return;
}
wp_safe_redirect( home_url() );
exit;
}
Upvotes: 1