Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
WooCommerce custom order action does not work with trash status

I want to use woocommerce hook woocommerce_order_status_changed. I want to fire something when new status of order is trash.

I used this function, which is working good for rest order statuses, except trash.

This is my code:

function custom_order_actions ( $order_id, $old_status, $new_status ){
  $order = new WC_Order($order_id);

  if ($new_status == 'trash') {
    // Do something
  }
}
add_action( 'woocommerce_order_status_changed', 'custom_order_actions', 99, 3 );
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

woocommerce_order_status_changed can not pick up the trash status since it's not one of the registered statuses on woocommerce according to their github page.

However, you could use wp_trash_post action hook instead!

add_action('wp_trash_post', 'custom_order_actions');

function custom_order_actions($order_id)
{

    if ('shop_order' == get_post_type($order_id)) {
        $order = new WC_Order($order_id);
        // Do something
    }
    
}

wp_trash_postDocs

Let me know if it works for you!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!