Discontinued Products developer reference

Actions and filters for reacting to Discontinued Products status changes and adjusting what it hides.

Beka Rice Avatar

Written by

Last updated


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.

ParameterTypeDescription
$product_idintID of the variable product.

wdp_after_ajax_variations_discontinued

Fires after the Set Status – Discontinued bulk action has discontinued every variation.

ParameterTypeDescription
$productWC_Product_VariableThe variable product.
$variationsarrayThe 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.

ParameterTypeDescription
$productsarrayThe products that were switched.
$variationsarrayThe 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.

ParameterTypeDescription
$productsarrayThe products set back to discontinued.
$variationsarrayThe individual variations set back to discontinued.
$variable_productsarrayThe 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.

ParameterTypeDescription
$checkboolWhether to subtract discontinued products. Default true.
add_filter( 'wcdp_should_count_discontinued_products', '__return_false' );

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.

ParameterTypeDescription
$hideboolWhether to hide discontinued products from search results.
add_filter( 'woocommerce_discontinued_products_hide_from_search', '__return_false' );

Keep learning