Change Woocommerce Out of Stock Text

Change Woocommerce Out of Stock Text

Astra adds a text 「Out Of Stock」 for the WooCommerece products that have 『Stock status』 as out of stock. Below is the screenshot of how the text displays in the front end on the product –

You can change the 「Out Of Stock」 text with any custom text you want, on both the Product Catalog (Shop page) and Single Product pages using filters.

You need to add the following filters to the functions.php file of your Child Theme:

Add the folowing code to change the 「Out Of Stock」 text on the Product Catalog (Shop page):

add_filter( 'astra_woo_shop_out_of_stock_string', 'out_of_stock_callback' );
function out_of_stock_callback( $title ) {
return 'SOLD';
}

Add the folowing code to change the 「Out Of Stock」 text on the Single Product pages:

add_filter( 'woocommerce_get_availability', 'change_out_of_stock_text_woocommerce', 1, 2 );
function change_out_of_stock_text_woocommerce( $availability, $product_to_check ) {
// Change Out of Stock Text
if ( ! $product_to_check->is_in_stock() ) {
$availability['availability'] = __('SOLD', 'woocommerce');
}
return $availability;
}

Both of these codes will replace the 「Out Of Stock」 text with 「SOLD」. You can modify this by replacing the bolded word 「SOLD」 in both codes with your custom text.

If you don』t have your Child Theme installed, please check this article on how to do it. If you are not sure how to add this code, please check this article.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注