问题
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