Search code examples
phpwoocommercehook-woocommerce

Action after the order status changed in dashboard - WooCommerce


I would like to execute my PHP code after the administrator manually changes the order status to completed in the Woocommerce dashboard. I have this but it doesn't work:

add_action( 'woocommerce_payment_complete', 'wenn_payment_complete' );
function wenn_payment_complete( $order_id ){
    $order = wc_get_order( $order_id );
    $customer_id = $order->get_customer_id();
    
    global $wpdb;
    $wpdb->query($wpdb->prepare("UPDATE lpd7_users SET new = '1' WHERE ID=$customer_id"));      
   
}

It is the right hook?


Solution

  • This hook will fired when the payment is completed. If you want to execute some code status changed from one to another you should use woocommerce_order_status_changed.

    This hook has three parameters: $order_id, $old_status, $new_status.

    You have to check inside your function if the new status is completed by checking the third $new_status.