Thanks for getting back so quick. I guess this is a corner case but I’d need to be able to inform customers if we’ve sold out of a gift.
I was able to put together a fix for use case with a nice little table on my cart page’s sidebar.
Orginal Code from https://stackoverflow.com/questions/32837586/how-to-display-stock-quantity-of-a-product-in-text-in-woocommerce
I modified it so it would output text if the given item is out of stock.
If anyone’s interested here’s the code, put it in your functions.php
Usage is [product_stock id=”16235″] where the id is the wordpress id not product sku.
add_shortcode('product_stock', 'product_stock');
function product_stock( $atts ) {
if ( ! $atts['id'] ) {
return '';
}
$product = get_product($atts['id']);
if ($product->stock < 1){
return 'Gift Out Of Stock'; // Message to show if gift is out of stock.
}
else {
return 'Only ' . $product->stock . ' Left'; // prints 22, ie the qty of product 1592
}
}