How to create a woocommerce discount on a product variation?

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 few clicks using WooCommerce All Discounts.

 

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 discounts rules or as target when creating a discount.

 

In order to create our list:

  1. Click on Discounts > Products Lists to access the lists management page.
  2. Click on New List to access the list creation page
  3. Select Dynamic Request as Extraction type
  4. 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:

    1. From the menu Products > Attributes

Woocommerce store 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 store 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:

woocommerce discount product variation attribute

 

    1. 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:

 

woocommerce discount product variation attribute

  1. Click on the Evaluate button to confirm that the plugin is able to fetch the variations properly.
  2. Click on the Publish button to save your list.
  3. 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 products 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:

woocommerce discount product variation attribute

 

Of course you’ll need to make sure the key matches the format depending on how the variation attributes were created as previously explained.

 

This completes our tutorial on the creation of discounts on the products variations based on their attributes using WooCommerce All Discounts. If you have any questions, use the comments section to ask.