Discontinued Products for WooCommerce has a few actions and filters for developers who need to react to its status changes or adjust what it hides. This article is for developers; if you’re not comfortable adding PHP to your site, ask your developer. For setup and settings, see Get started with Discontinued Products.
Discontinued products use the stock status discontinued, so $product->get_stock_status() === 'discontinued' tells you whether a product or variation is discontinued.
Actions
wdp_before_ajax_variations_discontinued
Fires before every variation of a variable product is discontinued with the Set Status – Discontinued bulk action on the Variations tab.
| Parameter | Type | Description |
|---|---|---|
$product_id | int | ID of the variable product. |
wdp_after_ajax_variations_discontinued
Fires after the Set Status – Discontinued bulk action has discontinued every variation.
| Parameter | Type | Description |
|---|---|---|
$product | WC_Product_Variable | The variable product. |
$variations | array | The variations that were discontinued. |
wdp_before_set_discontinued_products_to_outofstock
Fires once when the plugin is deactivated, before discontinued products and variations are switched to out of stock.
wdp_after_set_discontinued_products_to_outofstock
Fires once when the plugin is deactivated, after discontinued products and variations have been switched to out of stock.
| Parameter | Type | Description |
|---|---|---|
$products | array | The products that were switched. |
$variations | array | The individual variations that were switched. |
wdp_before_set_outofstock_products_back_to_discontinued
Fires once when the plugin is activated, before the products it switched to out of stock on deactivation are set back to discontinued.
wdp_after_set_outofstock_products_back_to_discontinued
Fires once when the plugin is activated, after those products have been set back to discontinued.
| Parameter | Type | Description |
|---|---|---|
$products | array | The products set back to discontinued. |
$variations | array | The individual variations set back to discontinued. |
$variable_products | array | The parent products of those variations, saved again so their own stock status updates. |
Filters
wcdp_should_count_discontinued_products
While Hide products is on, the product counts shown next to product categories and tags on your store leave out discontinued products, which takes an extra query per category or tag. Return false to skip those queries and show WooCommerce’s own counts.
| Parameter | Type | Description |
|---|---|---|
$check | bool | Whether to subtract discontinued products. Default true. |
add_filter( 'wcdp_should_count_discontinued_products', '__return_false' );
woocommerce_discontinued_products_hide_from_search
Whether discontinued products are left out of your site’s general WordPress search results, the ones that include posts and pages as well as products. Defaults to the Hide products setting. Return false to let them appear there. Product searches in your shop follow Hide products either way.
| Parameter | Type | Description |
|---|---|---|
$hide | bool | Whether to hide discontinued products from search results. |
add_filter( 'woocommerce_discontinued_products_hide_from_search', '__return_false' );
Keep learning
- Get started with Discontinued Products (setup, settings and common issues)
- How to add custom CSS to your site (styling the labels)
