How to add a Sold Out snippet or badge on a particular product using Woocommerce?
juanc4milo
Posted on November 13, 2020
This article is based on the description of how it would help solve a problem that I have encountered before related to the task ✍️ that @Chris Bongers left in Hashnode Bootcamp-II ⛺.
If you are setting up a Wordpress site with Woocommerce, notice when any product inventory is out of stock, there is nothing on the item catalog page to help you determine the product's stock availability.
For the customer it is annoying to click every product to see the stock availability.
To deal with that, there are 2 options that can help you :
✅ Function in PHP
In the * functions.php * file normally found in the Theme folder, insert the following code at the end of the file:
add_action ('woocommerce_after_shop_loop_item_title', 'talbiconsept_wc_template_loop_stock', 10);
function talbiconsept_wc_template_loop_stock () {
product $ global;
if ($ product-> stock management () && (int) $ product-> get_stock_quantity () <1)
echo '<p class = "stock out of stock">' .__ ('Sold out!'). '</p>';
}
✅ Add a plugin
In Wordpress Admin Desktop, go to the Plugins tab and look for "Out of Stock Badge for WooCommerce":
Then go to plugin settings and set text label, font size, font color, and background color:
And that is! 😎
Other articles that you might like...
- Redis - Instalación y Configuración
- AWS S3 Batch Operations
- AWS S3 Inventory
- Qué ofrece y cómo se configura AWS Elasticache?
- Qué ofrece y cómo se configura Elasticache en AWS?
- How to use Redis with Spring in Java
- How to send an email with AWS SES and track events with Configuration Sets?
- How to receive emails in a S3 bucket with AWS SES?
Do you like it? You can buy me a beer if you want.
Originally published at juanc4milo.dev
Posted on November 13, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 13, 2020