简体   繁体   English

隐藏WooCommerce变量产品上的“添加到购物车”按钮

[英]Hiding 'Add to Cart' button on WooCommerce variable products

I'm trying to hide the Add to Cart button when a variable product is at a certain stock level (so retailers and wholesalers see out of stock at different stock levels). 我试图隐藏Add to Cart按钮,当一个变量的产品是在一定的库存水平(因此零售商和批发商看到out of stock不同库存水平)。 I have managed to do this for simple products but am really struggling as to how to implement this with variable products. 我已经为简单的产品做到了这一点,但是在如何使用可变产品实现这一点上我确实很挣扎。

For the simple product I put 对于我放的简单产品

<?php 
if ( $product->get_stock_quantity() <= 2 && current_user_can('customer')) { 
    echo 'out of stock'; 
} else { //'add to cart' button }

I don't know if it's possible to implement something similar for variable products? 我不知道是否可以为可变产品实现类似的功能? Any help appreciated. 任何帮助表示赞赏。

从woocommerce获取产品ID,然后使用该产品ID实施您的代码。

At first glance, I think your if statement is evaluating incorrectly; 乍一看,我认为您的if语句评估不正确; you're missing brackets. 您缺少括号。

Try 尝试

<?php if ( ($product->get_stock_quantity() <= 2) && (current_user_can('customer'))) { 
echo 'out of stock'; } else { //'add to cart' button }

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

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