Variable products are a product type in WooCommerce that lets you offer a set of variations on a product, with control over prices, stock, image, and more for each variation. For various reasons, you may need to dynamically apply a discount on specific variations depending on their attributes.
In today’s article, you will learn how to create a discount on all product variations based on their attributes in a few clicks using Conditional Discounts for WooCommerce.
How to create a discount on a product variation with a specific attribute value?
In order to create a dynamic discount on product variations, we need to create a product list. A product list is a subset of your shop’s products that can be used in discount rules or as a target when creating a discount.
In order to create our list:
- Click on Discounts > Products Lists to access the lists management page.
- Click on New List to access the list creation page
- Select Dynamic Request as the Extraction type
- Scroll down to the metas section and let’s create a dynamic request based on the variation attributes that will allow us to get the variations we need.
There are two ways to create variation attributes, each way being stored differently by Woocommerce:
a- From the menu Products > Attributes
WooCommerce stores these as terms. Assuming our variable name is “Ring Style” and that their values are “Gold Rose”, “Silver” and “Gold”, WooCommerce will store them in the database as metas:
- Ring Style will be stored as attribute_pa_ring-style which is a combination of attribute_pa and the attribute name’s slug ( in lowercase, the spaces replaced by “-” and the special characters removed).
- Gold Rose will be stored as gold-rose which is the slug of the term.
- Silver will be stored as silver.
- Gold will be stored as gold.
In this case, the metas will be defined as below:
b- From the product creation page
WooCommerce stores them directly as meta but slightly differently:
- Ring Style will be stored as attribute_ring-style which is a combination of attribute_pa and the attribute name’s slug ( in lowercase, the spaces replaced by “-” and the special characters removed).
- Gold Rose will be stored as gold-rose which is the slug of the term.
- Silver will be stored as silver.
- Gold will be stored as gold.
In this case the metas will be defined as below:
- Click on the Evaluate button to confirm that the plugin is able to fetch the variations properly.
- Click on the Publish button to save your list.
- Now that you’ve created your list, you can use it in the discounts. Click on Discounts > New discount to create your discount and use the list we just created.
How to create a discount on all product variations with a specific attribute?
In case you need to create a discount on all variable products with a specific attribute no matter the value, you can follow the same steps but set up the metas a bit differently as below:
This completes our tutorial on the creation of discounts on product variations based on their attributes using Conditional Discounts for WooCommerce.
If you have any questions, Kindly drop them in the comment section 🙂