This is my first time using Craft Commerce. I have a client which needs to have multiple prices for a product. Customers are in one of three price level groups. Each price level group has a price unique to them as a variant. How do I get only the one variant for the appropriate price?
Here is what I tried, but returned all the variants for each price level instead of just one.
<select name="purchasableId">
{% set purchasable = craft.commerce.products %}
{% for purchasable in product.variants %}
<option
{% if purchasable.stock <= 0 and purchasable.unlimitedStock == false %}disabled {% endif %}
value="{{ purchasable.purchasableId }}">
Product Number: {{ product.stockDescription1 }} |
Price:
{% if currentUser.isInGroup( 'priceLevelOne' ) %}
{% set variant = craft.commerce.variants %}
{% for variant in product.variants %}
{% if variant.priceLevel1 == 1 %}
Product Number: {{ product.stockDescription1 }} |
Price:
{{ variant.price|currency(cart.currency) }}
{% endif %}
{% endfor %}
{% elseif currentUser.isInGroup( 'priceLevelTwo' ) %}
{% set variant = craft.commerce.variants %}
{% for variant in product.variants %}
{% if variant.priceLevel1 == 2 %}
Product Number: {{ product.stockDescription1 }} |
Price:
{{ variant.price|currency(cart.currency) }}
{% endif %}
{% endfor %}
{% elseif currentUser.isInGroup( 'priceLevelThree' ) %}
{% set variant = craft.commerce.variants %}
{% for variant in product.variants %}
{% if variant.priceLevel1 == 3 %}
Product Number: {{ product.stockDescription1 }} |
Price:
{{ variant.price|currency(cart.currency) }}
{% endif %}
{% endfor %}
{% endif %}
</option>
{% endfor %}
</select>
relatedTo
query to get the one you want, I can provide an example below!