Last Updated on January 7, 2022 by LAUNCHTIP
How to change the product price if the customer contains a specific tag
You might want to give some customers certain perks depending on their past behavior or their total cart amount. For instance, you may want to deduct 20% off a price if a customer has a certain tag.
How do you do this in Shopify? Is there an app to help? Below, we discuss the available options.
Changing the product price for certain customer tags
To change the product price for customers with a certain tag, you can use the Math filter in Shopify. The filter lets you apply mathematical tasks in your store.
For instance, you can minus, divide, add, or times.
So, you can begin with this code:
{% if customer.tags contains 'Premium' %} {{ variant.price - 45.00 | money }} {% else %} {{ settings.free_price_text }} {% endif %}
Then, you can use the Math filter to minus or times a product price accordingly.
You save {{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price }}%
Another way you can change the price for a product for customers with specific tags is by creating two tags for the customers. The first tag should tell which customers are eligible for this different price. The second tag should tell how the price will be changed. This requires the Shopify Plus App “Script Editor“.
Once you’ve created the tags, you can use this code:
TAG = "PRO" #customer tag DISCOUNTS_BY_TAG = { #array of discounts "PRO25" => 25, "PRO30" => 30, "PRO35" => 35, "PRO40" => 40, "PRO45" => 45, "PRO50" => 50, "BETA" => 90, } MESSAGE = "Pro discount" #this is the text that appears next to discount credit customer = Input.cart.customer if customer #checks to see if user is logged in if customer.tags.include?(TAG) #checks to see if user has appropriate discount tag DISCOUNTS_BY_TAG.each_pair do |tag, discount| #cycle through the above array of tags if customer.tags.include?(tag) #pairs the customer's discount level from the above array of tags discount = #{discount} Input.cart.line_items.each do |line_item| line_item.change_line_price( line_item.line_price * (Decimal.new(1) - discount / 100), message: MESSAGE, ) end end end end end Output.cart = Input.cart
Note: You have to input this code in the Script Editor app to apply the changes.