简体   繁体   中英

How to customize in stock and out of stock section in Woocommerce PRODUCT CATALOG

so everybody knows that in order to change the text for In stock and out of stock in the individual product pages you do

function wcs_custom_get_availability( $availability, $_product ) {

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

However, in the product catalog page, where you search for products, the message doesn't change there.

What do I have to do in functions.php to change that text?

woocommerce_after_shop_loop_item_title can be changed depending where you want it placed.

Try the following function -

function show_product_status_catalog() {
    global $product;  
    // Change In Stock Text
    if ( $product->is_in_stock() ) {
        $availability['availability'] = __('Available!', 'woocommerce');
    }
    // Change Out of Stock Text
    if ( ! $product->is_in_stock() ) {
        $availability['availability'] = __('Sold Out', 'woocommerce');
    }
    echo  $availability['availability'];
}
add_action( 'woocommerce_after_shop_loop_item_title', 'show_product_status_catalog' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM