简体   繁体   English

显示Woocommerce中选定的缺货产品

[英]Show selected out of stock products In Woocommerce

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-). 默认情况下,Woocommerce设置设置为“隐藏缺货的产品”,但是她希望选择一些产品并显示它们(即使库存为0,因为她想告诉他们的客户那几款产品即将面世-对此有文字-)。

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... 我们使用钩子woocommerce_product_is_visible尝试了一个非常简单的代码段,我们认为它可以正常工作,但是仍然缺少某些功能...

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. 任何帮助表示赞赏。

Why you don't simply use a Woocommerce shortcode like: 为什么不简单地使用Woocommerce短代码,例如:

1) In the Wordpress text editor of a page or a post (or in a widget): 1)在页面或帖子(或小部件中)的Wordpress文本编辑器中:

[products ids="18013,18050"]

2) In any PHP code file: 2)在任何PHP代码文件中:

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

The products out of stock are displayed just like in this real example: 像下面的实际示例一样显示缺货的产品:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM