Reply 192153 to: Stock amount on shop page

Avatar: Olga Barlow
Olga Barlow
Support staff
April 30, 2018 at 10:58

Hello,

Please add following code in child theme’s functions.php file :

//Add stock status to archive pages

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

If you want to change the styles use

.product .product-details .stock {
    /*==place your rules here==*/
    margin-bottom: 10px;
}

Regards

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.