• Resolved jlstysis

    (@jlstysis)


    Hello,

    I’d love to use your plugin but I need different out of stock messages for different categories. I found the following code, which works well on its own, but I have not been unable to combine it with your plugin. If you could offer some assistance, it would be most appreciated.

    function filter_woocommerce_get_availability( $availability, $product ) {
        // Specific categories
        $specific_categories = array( 'category-1', 'category-2' );
        
        // Out of stock and has certain category     
        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', 'filter_woocommerce_get_availability', 10, 2 );
    • This topic was modified 2 years, 5 months ago by jlstysis.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Charlie Etienne

    (@charlieetienne)

    Hi @jlstysis,

    Could you try this code and let me know ?

    
    add_filter( 'wcsob_soldout', function( $badge_html, $post, $product ) {
    	// Specific categories
    	$specific_categories = array( 'category-1', 'category-2' );
    
    	if ( has_term( $specific_categories, 'product_cat', $product->get_id() ) ) {
    		$custom_badge_text = __( 'My custom text', 'woocommerce' );
    
    		return '<span class="wcsob_soldout">' . $custom_badge_text . '</span>';
    	}
    
    	return $badge_html;
    }, 10, 3 );
    

    Regards,

    Charlie

    Thread Starter jlstysis

    (@jlstysis)

    Works beautifully!
    Thank you so much!!!

    Plugin Author Charlie Etienne

    (@charlieetienne)

    Thanks to you ??

    Cheers,

    Charlie

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change by catogory’ is closed to new replies.