Are you looking to customize the “out of stock” message displayed on your WooCommerce store? Whether you want to add a personal touch or match it to your branding, this simple code snippet will allow you to change the default message.
First, log in to your WordPress dashboard.
In the WordPress dashboard, navigate to **Appearance > Theme Editor**.
Once in the Theme Editor, locate the `functions.php` file on the right-hand side. This file contains functions that allow you to modify various aspects of your theme.
Copy the following code snippet:
<?php add_filter('woocommerce_get_availability_text', 'customwm_change_soldout', 10, 2 ); /** * Change Sold Out Text */ function customwm_change_soldout ( $text, $product) { if ( !$product->is_in_stock() ) { $text = '<div class="custom-sold-m">Sold out.</div>'; } return $text; } ?>
Paste this code at the bottom of the `functions.php` file.
After pasting the code, click on the “Update File” button to save your changes.
Visit your WooCommerce store and navigate to a product that is currently out of stock. You should see the updated “out of stock” message according to the changes you’ve made.
Congratulations! You’ve successfully customized the “out of stock” message in WooCommerce. Feel free to modify the text within the code snippet to suit your preferences or branding. If you encounter any issues, you can easily revert the changes by removing the added code from the `functions.php` file.