skip to Main Content

I’m currently working on the shopify site for the B2B company where i work.
(Yeah, we know that Shopify Plus is the best option for B2Bs, but we can’t afford the price)
We work on two different customer lists and really need two different prices to show to customers on the main-product page.
I managed the lists with customer tags, and also the two different prices with Variants.

Now i was trying to figure out how to show the Price of the Variant 1 to customers with the "list1" tag and the Price of the Variant 2 to customers with the "list2" tag.

(Yeah, we know that there are Wholesale Pricing app to do this, but we can’t afford the monthly cost either).

I tried something like this, but i’m stuck…

Could you please help me out?

This is my last try:
{% if customer.tags contains "list1" %}
   {% assign current = product.selected_or_first_available_variant %}
     {%- assign target_variant = product.variants[0] -%}
       <div class="no-js-hidden" id="variantPrice-{{ section.id }}" role="status" {{ block.shopify_attributes }}>
       {%- render 'price', product: product, use_variant: true, show_badges: true, price_class: 'price--large' -%} </div>                     
{% else %}
    {% assign current = product.selected_or_first_available_variant %}
      {%- assign target_variant = product.variants[1] -%}
        <div class="no-js-hidden" id="variantPrice-{{ section.id }}" role="status" {{ block.shopify_attributes }}>
        {%- render 'price', product: product, use_variant: true, show_badges: true, price_class: 'price--large' -%} </div>
{% endif %}

3

Answers


  1. Chosen as BEST ANSWER

    I somehow managed to solve this. After being stuck on it for two days :P It works with something like this:

    {%- when 'price' -%}
       {% if customer %}//Hide the price if not registered - endif is at the end//
         {% if customer.tags contains "list1" %}
           {%- assign target_variant = product.variants[0] -%}
            <div class="no-js-hidden" id="price-{{ section.id }}" role="status" 
            {{block.shopify_attributes }}> 
            {%- render 'price', product: product, use_variant: true, show_badges: true, 
             price_class: 'price--large' -%} </div> //It shows the price of the First Variant//                
          {% else %}
            {%- assign target_variant = product.variants[1] -%}//I can't figure out if this is relevant for the code, but it works like this, so...//
             <div id="variantPrice" role="status" {{ block.shopify_attributes }}>{%- render 'price' -%} </div>  //It shows the price of the Second Variant //    
          {% endif %}

    I don't know if this is the correct way, but it works, so it's fine :P Hope it will help someone with the same issue.


  2. The interesting thing about your approach here is that a customer from List type 1 would be seeing the price for the variant as List type 1 price, but there is zero stopping them from simply placing the variant with the different price from List type 2 in the cart if they wanted.

    In other words, you are decorating the price displayed, which is your goal I guess, but there is no actual logic in place to ensure customers pay the correct amount. For that, you would need a different logic, one that tries hard to ensure a customer from List type 1 only gets to checkout with product variants that are assigned to List type 1. Without that logic, you’re wide open to a bit of price abuse.

    Login or Signup to reply.
  3. The approach may be very straight to the point:

    {% if customer %}
        {% for variant in product.variants %} 
            {% assign current = forloop.index | plus: 1 | prepend:'list' %} 
            {% if customer.tags contains current %} 
                {{ variant.price}} 
                {% assign found =  true %} 
            {% endif %} 
        {% endfor %} 
        {% unless found %} 
            Display what you want to if no price has been found for logged in user
        {% endunless %} 
    {% else %}
        What you want to display when customer is not connected to an account. 
    {% endif %}
    

    You may use the same logic for your add to cart form.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search