Support » Plugin: WooCommerce » Out of Stock Message

  • Resolved krysteleal

    (@krysteleal)


    Hello! I have a question.

    On this product: https://www.rebento.pt/loja/mae/almofada-carocos-cereja
    I have three variations (3 different colors). Only one (“Creme”) is available. I want that if the client selects one of the colors that are out of stock, a message appears (like the one saying “disponível!” for the available color).

    I have this function in my functions.php but the entry for the “out of stock” (Esgotado) message doesn’t work:

    add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
    function wcs_custom_get_availability( $availability, $_product ) {
    
    // Change In Stock Text
    if ( $_product->is_in_stock() ) {
    $availability['availability'] = __('Disponível!', 'woocommerce');
    }
    // Change Out of Stock Text
    if ( ! $_product->is_in_stock() ) {
    $availability['availability'] = __('Esgotado', 'woocommerce');
    }
    return $availability;
    }

    Am I doing something wrong?

    Thanks in advance for any help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Try the woocommerce_get_availability_text filter maybe instead?

    
    add_filter( 'woocommerce_get_availability_text', 'wcs_custom_change_availability_text', 15, 2 );
    function wcs_custom_change_availability_text( $availability, $product ) {
    	if ( ! $product->is_in_stock() ) {
    		$availability = __( 'Esgotado', 'woocommerce' );
    	}
    
    	return $availability;
    }
    

    Also, if there are only three variations, it should be easy to hide out of stock ones if that is something you are interested in? The latest version of WC should be doing that for you automatically.

    Plugin Support Joel Williams

    (@joelwills)

    Automattic Happiness Engineer

    Hi there!

    There hasn’t been a reply for a while so I’m going to close this ticket.

    If you’re still having problems please open a new ticket, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Out of Stock Message’ is closed to new replies.