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). 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; 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 }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.