Home > OS >  Woocommerce change in stock text by category
Woocommerce change in stock text by category

Time:08-10

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~!

CodePudding user response:

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 );

CodePudding user response:

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  >' .  $availability['availability'] = $product->get_stock_quantity() . __( '   Rodapés', 'woocommerce' ) . '</div>';   } 
        }

This worked for me :)

  • Related