1
votes

I'm trying to find a solution to a client demand, without success. She's asking me how to show a selected number of out of stock products on her online store. By default, the Woocommerce setting is set to "hide out of stock products", but she wants to select some of her products and show them (even with 0 stock, because she wants to tell their customers that those few products will be available soon -there is a text for this-).

We have tried with a very simple snippet using the hook woocommerce_product_is_visible that we thought it would work, but there is something that we are missing...

This is de code:

// [WooCommerce] Show some out of stock products even the hide option is active
add_filter( 'woocommerce_product_is_visible', 'keep_showing_specific_out_of_stock_product_list', 10, 2 );
function keep_showing_specific_out_of_stock_product_list( $visible, $product_ID ){

    $product_list = array( 18013, 18050 ); // Insert the products IDs that want to show

    return in_array( $product_ID, $product_list )? true : $visible;
}

Any help is appreciated.

1

1 Answers

0
votes

Why you don't simply use a Woocommerce shortcode like:

1) In the Wordpress text editor of a page or a post (or in a widget):

[products ids="18013,18050"]

2) In any PHP code file:

echo do_shortcode( "[products ids='18013,18050']" );

The products out of stock are displayed just like in this real example:

enter image description here