Variable products are a product type in WooCommerce that lets you offer product variations, with control over prices, stock, image and more for each variation. For various reasons, you may need to dynamically apply a WooCommerce variable pricing on specific variations depending on their attributes.

In today’s article, you will learn how to create a variable pricing on all product variations based on their attributes in few clicks using Conditional Discounts for WooCommerce.

How to create a WooCommerce variable pricing on a product variation with a specific attribute value?

In order to create a dynamic WooCommerce variable pricing on product variations, we need to create a product list. A product list is a subset of your shop’s products that you can use in discounts rules or as target when creating a discount. This WooCommerce bulk discount demo will show you how to go about it.

In order to create our list:

  1. Click on Discounts > Products Lists to access the lists management page.
  2. Next click on New List to access the list creation page
  3. Then 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, you can store each way differently on WooCommerce:

a) From the menu Products > Attributes

WooCommerce store these as terms. Furthermore 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).
  • and Gold Rose will be store as gold-rose which is the slug of the term.
  • likewise Silver will be stored as silver.
  • Gold will be stored as gold too.

In this case the metas will be appear as below:

woocommerce discount product variation attribute

b) Also 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 appear 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. Then click on the Publish button to save your list.
  3. Now that you’ve created your list, you can use it in the discounts. Next click on Discounts > New discount to create your discount and use the list we just created.

How to create a WooCommerce variable pricing on product variations with a specific attribute?

For instance you need to create a WooCommerce variable pricing on all variable products with a specific attribute no matter the value,  you can follow the same steps in the demo above but setting up the metas a bit differently as below:

 

woocommerce variable pricing

 

Therefore you’ll need to make sure the key matches the format and it will depend on how you created the variation attributes based on the previous explanations.

This finally completes our tutorial on the creation of WooCommerce variable pricing on product variations based on their attributes using Conditional Discounts for WooCommerce. We hope the WooCommerce bulk discount demo helped you? If you have any questions, use the comments section to ask.

2 comments

  1. JAMES

    Thank you for this in-depth tutorial. I am trying to work on product variations but not getting the actual results as I have already gone through several resources and following this resource https://wpitech.com/woocommerce-product-variation/ to implement the product variation process. Can you please describe me further how to do this? This is the code that I think is somehow wrong. Is there any other way to set product variations?

    $variation_id = woo_insert_post( $variation_post );
    $variation = new WooCommerce_Product_Variation( $variation_id );
    foreach ($variation_data[‘attributes’] as $attribute => $term_name )

    October 15, 2019 at 8:14 pm
    Reply
    • Hermann

      Hello,
      I’m sorry i’m a bit confused. What exactly do you want to do?

      October 15, 2019 at 9:42 pm
      Reply

Leave a comment

Your email address will not be published. Required fields are marked *