e1commerce.com
Ask a question
  • New questions
  • With the answers
  • Unanswered
  1. Home
  2. How to display different variant prices to different customers? (Shopify/Liquid)

805 votes
2 answers

How to display different variant prices to different customers? (Shopify/Liquid)

Solution:

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 %}

Undefined asked
2022-12-2


12
votes

Answer

Solution:

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.

Undefined answered
2022-12-2
Link to answer


480
votes

Answer

Solution:

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.

Undefined answered
2022-12-2
Link to answer


Source

Didn't find the answer?

Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

816 shopify - How to store value from loop in liquid to display it into the variable
969 liquid - How to no-index specific pages on shopify? Don't want to use "contains" example for shopify, can I just type "="? And what denotes as the handle?
16 themes - Shopify Section load event in Liquid file (Shopify)
839 shopify - How do I use a liquid object array in alpine x-data?
484 php - Shopify shows CSP error when I try to redirect my app within the iframe
696 reactjs - Can I use Next.js frontend app as Block in Shopify's Theme App Extensions instead of liquid?
89 Showing shopify shipping rates based on weekday
766 ruby - How to display array values in Shopify Script Editor?
209 How to create Shopify app that provides custom fields (inputs) on product detail pages?
90 shopify - dynamically calling liquid commands

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.







Latest questions:

716 Triggering Zapier on new Shopify order containing a specific product

979 javascript - Swiper js - How can i change the background color of the selected slide

604 Shopify Webhooks not redirect into Laravel Route

292 How to enable / disable my app that is being managed from theme customization section shopify

608 Shopify List Blog Tags



© 2021

E-mail: infot@e1commerce.com