It depend if you’re using HPOS or not:
If not:
function my_custom_function_on_order_trash( $post_id ) {
// Get the post type of the trashed item
$post_type = get_post_type( $post_id );
// Check if the trashed item is an order
if ( 'shop_order' === $post_type ) {
// Your custom code here
}
}
add_action( 'wp_trash_post', 'my_custom_function_on_order_trash' );
If you’re using HPOS (High-Performance Order Storage) in WooCommerce, orders are no longer treated as standard posts, so wp_trash_post might not be the best hook to use. Instead, you should use WooCommerce-specific hooks to detect when an order is being moved to the trash.
Here’s how you can achieve that with HPOS:
function my_custom_function_on_order_trash( $order ) {
if ( $order instanceof \Automattic\WooCommerce\Orders\Order ) {
// Your custom code here
}
}
add_action( 'woocommerce_before_trash_order', 'my_custom_function_on_order_trash' );
Related Posts:
- Woocommerce – Hide a Column in Cart Table
- How do I change the initial quantity of a product in woocommerce?
- how to add custom functionality after woocommerce place order button
- Remove an action by extending class and replacing it
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Hide one specific woocoomerce product
- how to retrieve post_id under woocommerce_add_to_cart_validation hook?
- woocommerce single product page hook not working
- Woocommerce: block user removing cart item
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- Custom fields in the billing address section woocommerce
- Are woocommerce_thankyou hook and is_order_received_page() redundant? [closed]
- flush rewrite rules after plugin update?
- When does save_post hook fire on post save/update
- Plugin does not add action
- Woocommerce order empty items array
- Add child pages to submenu automatically
- After plugin activation hook
- How to get all product in the woo-commerce? [closed]
- How to replace default comments with custom HTML?
- Odd map_meta_cap $args on post edit — sometimes integer, sometimes string
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- How can I create a custom plugin that allows anonymous users to signup without registering?
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- Is there an admin hook that will let me read GET variable before it’s too late to set the header Location
- Why enqueue styles on hook?
- What’s the hook for filtering every texts of site?
- Woocommerce inventory [closed]
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- Associate multiple email addresses with the same user account, so they can log in with either
- Run command “composer install” when activating wordpress plugin
- How to change WooCommerce loop product title HTML output in single product page and archive page
- Can woocommerse be used dynamically for billing from another plugin for payment processing?
- Sending an SMS on new order placed – WooCommerce
- Update variable value via add_filter
- Can we use a library under MIT license in a WooCommerce plugin?
- Add a check box in Menu Settings
- Set _regular_price 0 if empty in woocommerce product
- Custom filter not working
- hook update_option/updated_option empty $old_value and $value
- WooCommerce Endpoints content
- How remove trashed WooCommerce orders from wc_get_orders() result?
- How to call code when adding WooCommerce menu items via woocommerce_account_menu_items
- Duplicate shipping method logic to another shipping method [closed]
- Custom Plugin Options Won’t Update
- Configure WordPress to Generate Scheme-less Relative URLs
- Woocommerce – Provide Associated Category Link for Product List Plugin [closed]
- How to find list of all functions bind to a particular hook from my plugin?
- get_shipping_methods() return empty rate
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Ajax +wordpress onClick link redirect to new page and create html content
- How to replace settings in WordPress plugin from a theme
- Redirect returning users to a certain page?
- Restrict certain actions to plugin-specific admin menu pages only
- Remove Products From Category
- want to show CMB2 metabox on woocommerce product data tab
- wp_schedule_single_event is set correctly but sometimes not fired
- Dynamic page generation upon purchase of a product
- Customise Grouped Product display in Woocommerce with custom column
- Creating posts with links from a txt file
- Change reminder email date to 14 days before
- Set the payment processor callbacks to a plugin
- Make a php array load faster
- How to make every image title equal to alt text(wordpress/woocommerce)?
- Create Woocommerce product without creating api credentials
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- Getting Post ID at “stylesheet” and “template” hooks
- Pass Values in URL on WooCommerce Product Page
- Woocommerce place order update shipping price
- Add custom product data using javascript when add to cart button is clicked
- How to enhance a self developed plugin by its own plugin architecture
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- product-attribute-slug-is-too-long-28-characters-max
- How to update global variables in plugin activation callback?
- Woocommerce get_term_by() in transition_post_status hook doesn’t works
- Add two button to page and post admin to redirect to : add new & list of (posts – pages) just after saving post or page
- `registration_errors` filter doesn’t seem to be called
- How to grab data after wp user search is complete
- Limit get_next_post to posts from the same author
- Trying to run a Ajax request from a checkout form in woocommerce via a custom plugin
- “add to cart” links css class “ajax_add_to_cart” doesn’t show in woocommerce in widget sidebar
- Securing custom rest API endpoints with public access from PWA
- How do I add filter with woocommerce categories?
- WooCommerce – Stop assigning order numbers
- Adding customs fields on each product on the cart
- Override woocommerce loop-start.php from theme using plugin?
- Getting products information, in woocommerce based on products ID
- How to direct WordPress to load custom template for custom post type
- Any way, hook to add content right before the “read more” link?
- Is there any way to get post meta from publish_post hook?
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- Add a custom submenu under submenu in a Custom WordPress Plugin
- PHPUnit Testing and woocommerce Constant
- Redirect WooCommerce checkout to cart
- WC REST API Error Handling
- How do I ensure I can loop through every enqueued script and CSS?