This article will be helpful for people who want to provide a discount based on the purchase of products with specific attributes.
Different scenarios:
Discount on mug on purchase "M" size T-shirts.
Discount on a specific "S" T-shirt on the purchase of "L" sized T-shirts.
Discount on a specific "L" T-shirt on purchase on "L" sized T-shirts.
The right way of using attributes in your products
Step 1: Pre-define the Attributes
VERY VERY IMPORTANT: When you create a variable product, always pre-define the Attributes in the Products -> Attributes section
Step 2:
Then, when you create the Variable product, choose these attributes, and add.
Now associate the attribute values and check the "Used for variations" checkbox.
IMPORTANT: Please DO NOT select the "custom product attribute".
If you use "Custom Product Attributes" that is created on-the-fly, then the attribute specific discount will NOT apply. Because WooCommerce does not create any attributes when you use a custom product attribute.
Let us create an example rule :
Navigate to Woocommerce -> Woo Discount Rules -> Add New Rule.
After Entering into the rule page, just add the rule name and you can select the desired discount adjustment type from the Drop-down.
Scenario 1 :
Discount on M-sized Tshirts.
Product Adjustment is chosen and since our discount scenario applies to an attribute, you can choose Attributes in the filter.
Here is a screenshot of rule setup:
Screenshot of cart page:
Scenario 2:
Provide a free product on purchase "M" size T-shirts.
Buy X get Y is chosen and the discount product is entered in the Get Discount.
Here is a screenshot of rule setup:
Screenshot of cart page:
Advanced Scenario
Buy one get one Free/discount with the attributes.
Apply Discount within the L sized T-shirts.
You can choose to apply within the cheapest/highest priced.
In order to achieve your requirement, we must first load the attribute in the category dropdown in our plugin.
You can load Attributes in Category listing via a code snippet. Then you can choose the attribute to which the Buy X Get Y cheapest applies to.
Please follow these steps below:
Step 1:
Load Attribute in the Category list
To load the attributes like categories, you can use this snippet --> https://gist.github.com/AnanthFlycart/5c1d29ea318550bc35a90747db9f6d30
Note: For attributes, the taxonomy will start with prefix pa_ in the above snippet. You can replace the attribute which you would like to load for example "pa_size" in the 4th line.
You can install this snippet via code snippet plugin.
Here is a guide which might be of help :
https://docs.flycart.org/en/articles/2404915-using-code-snippets-plugin
Step 2 :
Then you can set up the Buy X get Y type of discount for specific categories and select the attribute you want to give for discounts.
Here is a screenshot of rule setup:
Now, the discount will be applied to attribute "medium" in the cart.
Note :
The same approach can be adopted for other Buy One get One based Attribute Discount Rules as well.
Video:
I have more questions
Please submit a support request. We are always happy to assist you :)