Display always stock status without quantity in WooCommerce

风流意气都作罢 提交于 2020-08-09 09:20:17

问题


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?


回答1:


Resolved.

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

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




回答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' );


来源:https://stackoverflow.com/questions/48355379/display-always-stock-status-without-quantity-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!