Available quantity on shop page - by nixatsnow

This topic has 3 replies, 2 voices, and was last updated 3 years, 1 months ago ago by Olga Barlow

  • Avatar: nixatsnow
    nixatsnow
    Participant
    September 30, 2021 at 12:21

    Hi, how can i display the available quantity of the product in Product Content Elements in the shop page under each of the products? 4 in stock, 2 in stock etc..

    tried the below code and didnt work.

    add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_stock_shop', 10 );
      
    function bbloomer_show_stock_shop() {
       global $product;
       echo wc_get_stock_html( $product );
    }
    Please, contact administrator
    for this information.
    2 Answers
    Avatar: nixatsnow
    nixatsnow
    Participant
    September 30, 2021 at 12:36

    Display Stock Quantity/Status @ WooCommerce Shop Page article from https://www.businessbloomer.com/woocommerce-add-stock-quantity-on-shop-page/ does not seem to work..

    add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_stock_shop', 10 );
      
    function bbloomer_show_stock_shop() {
       global $product;
       echo wc_get_stock_html( $product );
    }
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    October 1, 2021 at 13:49

    Hello,

    It looks that wc_get_stock_html dislays nothing.
    You can try

    add_action( 'woocommerce_after_shop_loop_item_title', 'xstore_stock_catalog', 10 );
    function xstore_stock_catalog() {
        global $product;
        if ( $product->is_in_stock() ) {
            echo '<div class="et-stock" >' . $product->get_stock_quantity() . __( ' in stock', 'xstore-child' ) . '</div>';
        } else {
            echo '<div class="et-out-of-stock" >' . __( 'out of stock', 'xstore-child' ) . '</div>';
        }
    }

    Regards

  • Viewing 3 results - 1 through 3 (of 3 total)

The issue related to '‘Available quantity on shop page’' has been successfully resolved, and the topic is now closed for further responses

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.