Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinaPansuriya/6599c704c939850f4a136bd13de1f75a to your computer and use it in GitHub Desktop.
Save MinaPansuriya/6599c704c939850f4a136bd13de1f75a to your computer and use it in GitHub Desktop.
/**
* @Title: WooCommerce Display Specific "Out of Stock" Products on Shop Pages
* @Author: Mina Pansuriya
* @Website: http://minapansuriya.com
* Note: For complete tutorial visit: http://minapansuriya.com/woocommerce-display-selected-out-of-stock-products-on-shopcategory-pages/
*/
add_filter( 'woocommerce_product_is_visible', 'pbs_woo_disp_selected_out_of_stock_products', 2, 99 );
function pbs_woo_disp_selected_out_of_stock_products( $visible, $productId ) {
// Replace "6838" with your product post ID. If you want to hide multiple no. of out of stock products,
// add further product IDs in this if statement comparision.
if($productId == 6838)
{
// All the product here will be displayed.
}
else
{
$product = new WC_Product($productId);
if(!$product->is_in_stock())
{
$visible = false;
}
}
return $visible;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment