简体   繁体   English

woocommerce-仅显示少数产品的库存数量

[英]woocommerce - Show stock quantity only on few products

I'm currently working on an e-commerce platform and the client wants to have this functionality where only the products they have on sale, which are like 3 or 4 at the moment, display the stock quantity. 我目前正在电子商务平台上工作,客户希望具有此功能,即只有他们所销售的产品(当前为3或4)显示库存数量。

I know Woocommerce allows to show stock status of all the products, but I only need it to be displayed on the products they want to put on sale. 我知道Woocommerce允许显示所有产品的库存状态,但是我只需要在他们要销售的产品上显示它即可。

Is there a way to do this? 有没有办法做到这一点? , any guidance will be much appreciated! ,任何指导将不胜感激!

thanks in advance! 提前致谢!

Uncheck "Enable stock management at product level" in Inventory tab: 在库存标签中取消选中“在产品级别启用库存管理”:

产品

never mind, solved it. 没关系,解决了它。 It was so simple, I feel dumb for asking!. 真是太简单了,我真想问个问题!

Anyway here is the answer in case someone needs it. 无论如何,这是万一有人需要的答案。

in functions.php

add_action( 'woocommerce_after_shop_loop_item_title', 'my_stock', 15);
    function my_stock() {
    global $product;
    if ($product->stock > 0) {
         echo "stock: ".number_format($product->stock,0,'','');
    }

}

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

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