How can i change the add to cart button text when the product is out of stock. for now, the button text of products with out of stock is ‘Read More’ and i need to change it
The page I need help with: [log in to see the link]
How can i change the add to cart button text when the product is out of stock. for now, the button text of products with out of stock is ‘Read More’ and i need to change it
From what I understand, you would like to change the text on the ‘Add to Cart’ button when a product is out of stock. Currently, the button displays ‘Read More’ for out-of-stock products, and you would like to modify this.
To achieve this, you can use the following code snippet:
add_filter( 'woocommerce_product_add_to_cart_text', 'wc_archive_custom_cart_button_text' );
function wc_archive_custom_cart_button_text( $text ) {
global $product;
if ( $product && ! $product->is_in_stock() ) {
return 'Out of stock';
}
return $text;
}
?? In the above code, replace ‘Out of stock’ with whatever you want the button to display when a product is out of stock.
You should add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, like the Code Snippets plugin. Please note that it’s not advisable to add custom code directly to your parent theme’s functions.php file. Doing so could lead to the code being erased when the theme is updated.
?? Just a quick reminder: Before you make any changes, we strongly recommend that you create a backup of your full site and database. This is a crucial step to ensure that in case anything goes wrong, you can easily restore your site to its previous, functioning state.
I hope this helps! If you have any other questions or run into any issues, please don’t hesitate to ask.
I have add the code but the button text doesn’t change
Thank you for your quick response and for implementing the code provided. I’m sorry to hear that you’re still experiencing issues with the ‘Add to Cart’ button text not changing.
I have tried to access your website (https://empirefarm.co) to check the issue firsthand, but unfortunately, I was not able to view it as I just saw a blank white screen.
Could you please confirm if this is the correct URL? If so, it seems like there might be a larger issue at hand as your site should be visible. If it’s not the correct URL, please provide the correct one so I can further assist you.
Additionally, could you provide more details about the issue you’re experiencing? A screenshot of where you added the code and the ‘Add to Cart’ button that isn’t changing would be really helpful. You can share screenshots at https://snipboard.io. Just follow the instructions on the page and paste the URL in your response.
We would also appreciate seeing your site’s System Status report. It can give us a clearer picture of your site’s setup and help us identify the problem. You can find the report under WooCommerce > Status. Choose Get system report and then Copy for support.
If there are any fatal error logs, please share those as well. You can find them under WooCommerce > Status > Logs.
Once you’ve collected this information, please paste it inside a Code block in your reply, or use https://pastebin.com to paste it and share the link with us.
Thanks for your patience and cooperation in this matter! We’re here to help you get this sorted.