wordpress woocommerce action hook working on woocommerce android app but action hook not working on woocommerce admin wp-admin login

25 Views Asked by At

I am currently working on a WordPress/WooCommerce project where I have implemented a custom function to be triggered when an order's status changes to "completed." The code is set up as follows:

add_action('woocommerce_order_status_completed', 'custom_function_after_order_completed', 10, 1);

function custom_function_after_order_completed($order_id) {
    // Custom script execution logic here
    // ...
}

This setup works perfectly on the frontend, and the custom script is executed as expected when an order is marked as "completed." However, I've noticed that the hook does not work when the order status change is triggered within the WooCommerce admin dashboard.

I have checked the following:

The hook is registered correctly, and the callback function is defined.

PHP error logging is enabled, and there are no errors logged in the error log.

The order status is set to "completed" when testing.

The exec command is not the issue, as the script runs successfully on the WooCommerce app for Android.

It appears that the WooCommerce admin dashboard processes the order status change differently, and the hook is not triggered as expected.

Questions:

Is there a specific hook or method that should be used for order status changes initiated from the WooCommerce admin dashboard?

Are there any known differences in how order status changes are processed on the admin page compared to the frontend?

Are there any additional debugging steps I can take to identify why the hook is not working specifically on the WooCommerce admin page?

I appreciate any insights or guidance on resolving this issue.

I am trying to run a script after order status changes to 'complete' to trigger the script to my delivery backend.

  1. i have tried to hook using the ''completed email'' as trigger (only works on android app not admin)

  2. Also through post update

    add_action('transition_post_status', 'custom_function_after_post_status_transition', 10, 3);

     function custom_function_after_post_status_transition($new_status, $old_status, $post) {
     // Check if the post is a WooCommerce order
     if ($post->post_type === 'shop_order') {
         // Check if the transition is from 'pending' to 'completed'
         if ($old_status === 'wc-pending' && $new_status === 'wc-completed') {
             // Get the order ID
             $order_id = $post->ID; 
    
0

There are 0 best solutions below