Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter abluedeveloper

    (@abluedeveloper)

    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
      }
    }
    
    
    Thread Starter abluedeveloper

    (@abluedeveloper)

    I also tried putting a little note in the plugin settings telling customers if they don’t see a gift it’s out of stock.

    But on some items Say I only want 1 gift open but it’s out of stock it hides the whole area so I can’t even tell the customers it’s out of stock.

    PS great plugin. Thanks for the effort into it.

Viewing 2 replies - 1 through 2 (of 2 total)