skip to Main Content

So how a title says, I have a multiple product "test" website. And each product have " X in stock " in shop page.
My website is filtred by category like "Floors" and "Blinds".

And my question is how to I change and text " X in stock " to imagine "X Boxes in Stock". I want a simple solution to don’t affect another products category.

Like Floor’s category display: "X Boxes in Stock"
And Blind’s category display: "X Meters in Stock"

Something like that.

Thank you~!

2

Answers


  1. Chosen as BEST ANSWER
    add_action( 'woocommerce_after_shop_loop_item_title', 'xstore_stock_catalog', 10 );
        function xstore_stock_catalog() {
            global $product;
            if ( $product->is_in_stock() && has_term( 'rodapes', 'product_cat', $product->get_id() ) ) {
                echo '<div class="et-stock" >' .  $availability['availability'] = $product->get_stock_quantity() . __( '   Rodapés', 'woocommerce' ) . '</div>';   } 
            }
    

    This worked for me :)


  2. you can check it with this code

    
    function ak_woocommerce_get_availability( $availability, $product ) {
        // Specific categories
        $specific_categories = array( 'test', 'test-1' );
        
           
        if ( $product->is_in_stock() && has_term( $specific_categories, 'product_cat', $product->get_id() ) ) {
            $availability['availability'] = __('My custom text', 'woocommerce' );
        }
    
        return $availability;
    }
    add_filter( 'woocommerce_get_availability', 'ak_woocommerce_get_availability', 10, 2 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search