Support » Plugin: WooCommerce » Display stock availabilty on shop page, WooCommerce

  • How would I display the stock availability (for example, “9 items left”) for variable and single products on my shop page in WooCommerce, similar to how the following script displays the SKU number?

    function shop_inventory() {
    global $product;
    if ( $product->is_type( ‘variable’ )) {
    echo
    ‘<div itemprop=”productID” id=”multi-sku”>SKU
    <span>’ . $product->sku . ‘</span></div>’;
    }

    else {
    echo
    ‘<div itemprop=”productID” id=”multi-sku”>SKU
    <span>’ . $product->sku . ‘</span></div>
    <div class=”stock” ><span>’ . $product->stock . ‘</span> in stock<small>(backorders allowed)</small></div>’;
    }
    };

    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘shop_inventory’ );

    http://wordpress.org/extend/plugins/woocommerce/

  • The topic ‘Display stock availabilty on shop page, WooCommerce’ is closed to new replies.