How to Change WooCommerce out of Stock Text with Astra?
|
/ Documentation /Custom Code Snippets/WooCommerce Filters/ 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 –

Out of Stock WooCommerce

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.

For that, 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. And, if you are not sure how to add this code, please check this article.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
On this page

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

This field is required.

REWIND

YEAR IN REVIEW

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form