Stock amount on shop page - by Jarkko - on WordPress WooCommerce support

This topic has 4 replies, 2 voices, and was last updated 6 years, 8 months ago ago by Olga Barlow

  • Avatar: Laatusuklaa
    Jarkko
    Participant
    April 30, 2018 at 10:22

    Is it possible to show stock amount of each product on the shop page under the price? And maybe add a word or two in front of it?

    And how would I then modify the amount and text style with custom css?

    3 Answers
    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

    Avatar: Laatusuklaa
    Jarkko
    Participant
    May 2, 2018 at 17:57

    Thanks, I’ll try this tomorrow.

    It seems your forum is no longer sending notifications of replies..

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    May 3, 2018 at 14:24

    Hello,

    Thank you for the information. We’ll check our server.

    Regards

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

You must be logged in to reply to this topic.Log in/Sign up

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