Display always stock status without quantity in WooCommerce

13,981

Solution 1

Resolved.

Woocommerce -> Settings -> Products -> Inventory -> Stock Display Format.

...can't believe I didn't see it before.

Solution 2

If You have problem with 'In Stock' custom message try this code below:

add_filter( 'woocommerce_get_availability', 'custom_override_get_availability', 10, 2);

// The hook in function $availability is passed via the filter!
    function custom_override_get_availability( $availability, $_product ) {
    if ( $_product->is_in_stock() ) $availability['availability'] = __('In Stock', 'woocommerce');
    return $availability;
    }

or this

//* Add stock status to archive pages
function envy_stock_catalog() {
    global $product;
    if ( $product->is_in_stock() ) {
        echo '<div class="stock" >' . $product->get_stock_quantity() . __( ' in stock', 'envy' ) . '</div>';
    } else {
        echo '<div class="out-of-stock" >' . __( 'out of stock', 'envy' ) . '</div>';
    }
}
add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );
Share:
13,981
TomJones999
Author by

TomJones999

Updated on June 04, 2022

Comments

  • TomJones999
    TomJones999 about 2 years

    I would like to display the product stock status, without showing the remaining quantity.

    Right now, the standard WooCommerce stock display, as well as the plugins I found so far (WooCommerce Booster, etc), display either the quantity, or a "package deal" showing the quantity AND the phrase "in stock".

    In other words,

    I have: "5 in stock"

    I want to show: "In Stock"

    Is this possible? If so, how?