If customer tag contains TAG change price

KL4
New Member
9 0 0

Hi there forum!

Help me write this code! I want to subtract $45 dollars from the variant price

{% if customer.tags contains 'Premium' %}
  {{ variant.price - 45.00 | money }}               
                                           
{% else %}
{{ settings.free_price_text }}
{% endif %}

 

Anyone know how to make this work?

0 Likes
Jason
Shopify Expert
10187 135 1916

To do math operations you'd need to use Math filters.

{{ variant.price | minus:4500 | money }} 

 

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
KL4
New Member
9 0 0

Duh! Thank you! :)

0 Likes
jgy3183
Tourist
8 0 2

Did this also change the price for the cart/checkout, or did it just change the text on the screen?

0 Likes
PadraigCahill
Tourist
6 0 1

Hi,

 

This seems to be a very old thread so hopefully someone picks up on this.

 

I'm trying something similar and have used the Maths filters but still doesn't seem to be working. I'm trying to take 20% off for customers tagged "Trade".

 

I have put the following code on the product-template.liquid page. My edits are in bold.

 

<ul class="inline-list product-meta">
        <li>
          <span id="productPrice-{{ section.id }}" class="h1">
            {% if customer.tags contains 'Trade' %}
           {{ variant.price | divided_by: 100 | times:80 }}
            {% else %}
           {% include 'price' with variant.price %}
           {% endif %}
          </span>
        </li>
        {% if product.compare_at_price_max > product.price and section.settings.product_show_saved_amount %}
        <li>
          <span id="comparePrice-{{ section.id }}" class="sale-tag large">
            {% assign compare_price = variant.compare_at_price %}
            {% assign product_price = variant.price %}
            {% include 'price-sale' %}
          </span>
        </li>
        {% endif %}
        {% if section.settings.product_reviews_enable %}
          <li class="product-meta--review">
            <span class="shopify-product-reviews-badge" data-id="{{ product.id }}"></span>
          </li>
        {% endif %}
      </ul>

 

0 Likes
Fowlertown_Web_
Shopify Partner
18 1 3

@PadraigCahill All you've done by editing the template code is changing how the price is displayed to the user on that page. You've not affected the price change permanently.

 

Unfortunately I don't know of a way to make the change permanently except by using Shopify Wholesale Channel, which allows you to set custom price lists and assign them to customer tags, or by using Shopify's Script Editor app to affect lasting price change at the cart/checkout. Both of these features are available only to Shopify Plus stores.

 

What you've done, in combination with what I did using Script Editor (see below), would effectively provide you with a DIY method for discounting your prices based on customer tag. Yours is the visual change on the PDP, the script I wrote below applies a discount at the cart/checkout.

 

The way my script works is that a customer who is eligible for a discount must have two tags, one that identifies the customer as being eligible for a discount ("PRO"), and another that defines the discount amount (e.g. "PRO35" or "BETA").

 

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

This is a code snippet for a line item script in the Script Editor app. You should setup a customer how you want them to be tagged before trying to implement the script, and use the Script Editor to thoroughly test your script before publishing. Ideally, you're a programmer or advanced Shopify user if you're attempting to code your own discount in the Script Editor.

 

In my code snippet, you only need to edit the first 3 variables to suit your needs:

  1. TAG is the customer tag that will make a customer eligible for a discount
  2. DISCOUNTS_BY_TAG contains a handful of customer tags and defines the discount amount (percentage as decimal)
  3. MESSAGE is the text that appears alongside the discount in the cart/checkout.

 

0 Likes
Alex263
Tourist
8 0 5

Hi, I would like to offer another price for retail and professionals when they log in to the site, the price should be lower by 10% and 20%, respectively, how can I do this in percentages. Thanks

0 Likes