All things Shopify and commerce
Custom code to remove quantity selector on all products priced at $0.00? Using Dawn theme.
Can you please share you store's URL ?
@Hayes1234 hey, thanks for posting here.
can you please share the link to inspect it, thanks.
or put this condition on the quantity selector :
{% assign product_price = product.price | money_without_currency | replace: ',', '' | plus: 0 %}
{% if product_price > 0 %}
<div class="quantity-selector">
<!-- Your existing quantity selector code goes here -->
</div>
{% endif %}
Hi @Hayes1234
In sections/main-product.liquid file
Replace
<div
id="Quantity-Form-{{ section.id }}"
class="product-form__input product-form__quantity{% if settings.inputs_shadow_vertical_offset != 0 and settings.inputs_shadow_vertical_offset < 0 %} product-form__quantity-top{% endif %}"
{{ block.shopify_attributes }}
>
{% comment %} TODO: enable theme-check once `item_count_for_variant` is accepted as valid filter {% endcomment %}
{% # theme-check-disable %}
{%- assign cart_qty = cart
| item_count_for_variant: product.selected_or_first_available_variant.id
-%}
{% # theme-check-enable %}
<label class="quantity__label form__label" for="Quantity-{{ section.id }}">
{{ 'products.product.quantity.label' | t }}
<span class="quantity__rules-cart{% if cart_qty == 0 %} hidden{% endif %}">
{%- render 'loading-spinner' -%}
<span
>(
{{- 'products.product.quantity.in_cart_html' | t: quantity: cart_qty -}}
)</span
>
</span>
</label>
<div class="price-per-item__container">
<quantity-input class="quantity" data-url="{{ product.url }}" data-section="{{ section.id }}">
<button class="quantity__button" name="minus" type="button">
<span class="visually-hidden">
{{- 'products.product.quantity.decrease' | t: product: product.title | escape -}}
</span>
{% render 'icon-minus' %}
</button>
<input
class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
data-cart-quantity="{{ cart_qty }}"
data-min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
{% if product.selected_or_first_available_variant.quantity_rule.max != null %}
data-max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
{% endif %}
step="{{ product.selected_or_first_available_variant.quantity_rule.increment }}"
value="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
form="{{ product_form_id }}"
>
<button class="quantity__button" name="plus" type="button">
<span class="visually-hidden">
{{- 'products.product.quantity.increase' | t: product: product.title | escape -}}
</span>
{% render 'icon-plus' %}
</button>
</quantity-input>
{%- liquid
assign volume_pricing_array = product.selected_or_first_available_variant.quantity_price_breaks | sort: 'quantity' | reverse
assign current_qty_for_volume_pricing = cart_qty | plus: product.selected_or_first_available_variant.quantity_rule.min
if cart_qty > 0
assign current_qty_for_volume_pricing = cart_qty | plus: product.selected_or_first_available_variant.quantity_rule.increment
endif
-%}
{%- if product.quantity_price_breaks_configured? -%}
<price-per-item
id="Price-Per-Item-{{ section.id }}"
data-section-id="{{ section.id }}"
data-variant-id="{{ product.selected_or_first_available_variant.id }}"
>
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size > 0 -%}
{%- assign variant_price_compare = product.selected_or_first_available_variant.compare_at_price -%}
<div class="price-per-item">
{%- if variant_price_compare -%}
<dl class="price-per-item--current">
<dt class="visually-hidden">
{{ 'products.product.price.regular_price' | t }}
</dt>
<dd>
<s class="variant-item__old-price">
{{ variant_price_compare | money_with_currency }}
</s>
</dd>
</dl>
{%- endif -%}
{%- if current_qty_for_volume_pricing < volume_pricing_array.last.minimum_quantity -%}
{%- assign variant_price = product.selected_or_first_available_variant.price
| money_with_currency
-%}
<span class="price-per-item--current">
{{- 'products.product.volume_pricing.price_at_each' | t: price: variant_price -}}
</span>
{%- else -%}
{%- for price_break in volume_pricing_array -%}
{%- if current_qty_for_volume_pricing >= price_break.minimum_quantity -%}
{%- assign price_break_price = price_break.price | money_with_currency -%}
<span class="price-per-item--current">
{{-
'products.product.volume_pricing.price_at_each'
| t: price: price_break_price
-}}
</span>
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
</div>
{%- else -%}
{%- assign variant_price = product.selected_or_first_available_variant.price
| money_with_currency
-%}
{%- assign variant_price_compare = product.selected_or_first_available_variant.compare_at_price -%}
<div class="price-per-item">
{%- if variant_price_compare -%}
<dl class="price-per-item--current">
<dt class="visually-hidden">
{{ 'products.product.price.regular_price' | t }}
</dt>
<dd>
<s class="variant-item__old-price">
{{ variant_price_compare | money_with_currency }}
</s>
</dd>
<dt class="visually-hidden">
{{ 'products.product.price.sale_price' | t }}
</dt>
<dd>
<span class="price-per-item--current">
{{- 'products.product.volume_pricing.price_at_each' | t: price: variant_price -}}
</span>
</dd>
</dl>
{%- else -%}
<span class="price-per-item--current">
{{- 'products.product.volume_pricing.price_at_each' | t: price: variant_price -}}
</span>
{%- endif -%}
</div>
{%- endif -%}
</price-per-item>
{%- endif -%}
</div>
<div class="quantity__rules caption" id="Quantity-Rules-{{ section.id }}">
{%- if product.selected_or_first_available_variant.quantity_rule.increment > 1 -%}
<span class="divider">
{{-
'products.product.quantity.multiples_of'
| t: quantity: product.selected_or_first_available_variant.quantity_rule.increment
-}}
</span>
{%- endif -%}
{%- if product.selected_or_first_available_variant.quantity_rule.min > 1 -%}
<span class="divider">
{{-
'products.product.quantity.minimum_of'
| t: quantity: product.selected_or_first_available_variant.quantity_rule.min
-}}
</span>
{%- endif -%}
{%- if product.selected_or_first_available_variant.quantity_rule.max != null -%}
<span class="divider">
{{-
'products.product.quantity.maximum_of'
| t: quantity: product.selected_or_first_available_variant.quantity_rule.max
-}}
</span>
{%- endif -%}
</div>
{%- if product.quantity_price_breaks_configured? -%}
<volume-pricing class="parent-display" id="Volume-{{ section.id }}">
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size > 0 -%}
<span class="caption-large">{{ 'products.product.volume_pricing.title' | t }}</span>
<ul class="list-unstyled">
<li>
<span>{{ product.selected_or_first_available_variant.quantity_rule.min }}+</span>
{%- assign price = product.selected_or_first_available_variant.price
| money_with_currency
-%}
<span data-text="{{ 'products.product.volume_pricing.price_at_each' | t: price: variant_price }}">
{{- 'sections.quick_order_list.each' | t: money: price -}}
</span>
</li>
{%- for price_break in product.selected_or_first_available_variant.quantity_price_breaks -%}
{%- assign price_break_price = price_break.price | money_with_currency -%}
<li class="{%- if forloop.index >= 3 -%}show-more-item hidden{%- endif -%}">
<span>
{{- price_break.minimum_quantity -}}
<span aria-hidden="true">+</span></span
>
<span data-text="{{ 'products.product.volume_pricing.price_at_each' | t: price: price_break_price }}">
{{- 'sections.quick_order_list.each' | t: money: price_break_price -}}
</span>
</li>
{%- endfor -%}
</ul>
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size >= 3 -%}
<show-more-button>
<button
class="button-show-more link underlined-link"
id="Show-More-{{ section.id }}"
type="button"
>
<span class="label-show-more label-text"
><span aria-hidden="true">+ </span>{{ 'products.facets.show_more' | t }}
</span>
</button>
</show-more-button>
{%- endif -%}
{%- endif -%}
</volume-pricing>
{%- endif -%}
</div>
To
{% if product.price > 0 %}
<div
id="Quantity-Form-{{ section.id }}"
class="product-form__input product-form__quantity{% if settings.inputs_shadow_vertical_offset != 0 and settings.inputs_shadow_vertical_offset < 0 %} product-form__quantity-top{% endif %}"
{{ block.shopify_attributes }}
>
{% comment %} TODO: enable theme-check once `item_count_for_variant` is accepted as valid filter {% endcomment %}
{% # theme-check-disable %}
{%- assign cart_qty = cart
| item_count_for_variant: product.selected_or_first_available_variant.id
-%}
{% # theme-check-enable %}
<label class="quantity__label form__label" for="Quantity-{{ section.id }}">
{{ 'products.product.quantity.label' | t }}
<span class="quantity__rules-cart{% if cart_qty == 0 %} hidden{% endif %}">
{%- render 'loading-spinner' -%}
<span
>(
{{- 'products.product.quantity.in_cart_html' | t: quantity: cart_qty -}}
)</span
>
</span>
</label>
<div class="price-per-item__container">
<quantity-input class="quantity" data-url="{{ product.url }}" data-section="{{ section.id }}">
<button class="quantity__button" name="minus" type="button">
<span class="visually-hidden">
{{- 'products.product.quantity.decrease' | t: product: product.title | escape -}}
</span>
{% render 'icon-minus' %}
</button>
<input
class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
data-cart-quantity="{{ cart_qty }}"
data-min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
min="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
{% if product.selected_or_first_available_variant.quantity_rule.max != null %}
data-max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
max="{{ product.selected_or_first_available_variant.quantity_rule.max }}"
{% endif %}
step="{{ product.selected_or_first_available_variant.quantity_rule.increment }}"
value="{{ product.selected_or_first_available_variant.quantity_rule.min }}"
form="{{ product_form_id }}"
>
<button class="quantity__button" name="plus" type="button">
<span class="visually-hidden">
{{- 'products.product.quantity.increase' | t: product: product.title | escape -}}
</span>
{% render 'icon-plus' %}
</button>
</quantity-input>
{%- liquid
assign volume_pricing_array = product.selected_or_first_available_variant.quantity_price_breaks | sort: 'quantity' | reverse
assign current_qty_for_volume_pricing = cart_qty | plus: product.selected_or_first_available_variant.quantity_rule.min
if cart_qty > 0
assign current_qty_for_volume_pricing = cart_qty | plus: product.selected_or_first_available_variant.quantity_rule.increment
endif
-%}
{%- if product.quantity_price_breaks_configured? -%}
<price-per-item
id="Price-Per-Item-{{ section.id }}"
data-section-id="{{ section.id }}"
data-variant-id="{{ product.selected_or_first_available_variant.id }}"
>
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size > 0 -%}
{%- assign variant_price_compare = product.selected_or_first_available_variant.compare_at_price -%}
<div class="price-per-item">
{%- if variant_price_compare -%}
<dl class="price-per-item--current">
<dt class="visually-hidden">
{{ 'products.product.price.regular_price' | t }}
</dt>
<dd>
<s class="variant-item__old-price">
{{ variant_price_compare | money_with_currency }}
</s>
</dd>
</dl>
{%- endif -%}
{%- if current_qty_for_volume_pricing < volume_pricing_array.last.minimum_quantity -%}
{%- assign variant_price = product.selected_or_first_available_variant.price
| money_with_currency
-%}
<span class="price-per-item--current">
{{- 'products.product.volume_pricing.price_at_each' | t: price: variant_price -}}
</span>
{%- else -%}
{%- for price_break in volume_pricing_array -%}
{%- if current_qty_for_volume_pricing >= price_break.minimum_quantity -%}
{%- assign price_break_price = price_break.price | money_with_currency -%}
<span class="price-per-item--current">
{{-
'products.product.volume_pricing.price_at_each'
| t: price: price_break_price
-}}
</span>
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
</div>
{%- else -%}
{%- assign variant_price = product.selected_or_first_available_variant.price
| money_with_currency
-%}
{%- assign variant_price_compare = product.selected_or_first_available_variant.compare_at_price -%}
<div class="price-per-item">
{%- if variant_price_compare -%}
<dl class="price-per-item--current">
<dt class="visually-hidden">
{{ 'products.product.price.regular_price' | t }}
</dt>
<dd>
<s class="variant-item__old-price">
{{ variant_price_compare | money_with_currency }}
</s>
</dd>
<dt class="visually-hidden">
{{ 'products.product.price.sale_price' | t }}
</dt>
<dd>
<span class="price-per-item--current">
{{- 'products.product.volume_pricing.price_at_each' | t: price: variant_price -}}
</span>
</dd>
</dl>
{%- else -%}
<span class="price-per-item--current">
{{- 'products.product.volume_pricing.price_at_each' | t: price: variant_price -}}
</span>
{%- endif -%}
</div>
{%- endif -%}
</price-per-item>
{%- endif -%}
</div>
<div class="quantity__rules caption" id="Quantity-Rules-{{ section.id }}">
{%- if product.selected_or_first_available_variant.quantity_rule.increment > 1 -%}
<span class="divider">
{{-
'products.product.quantity.multiples_of'
| t: quantity: product.selected_or_first_available_variant.quantity_rule.increment
-}}
</span>
{%- endif -%}
{%- if product.selected_or_first_available_variant.quantity_rule.min > 1 -%}
<span class="divider">
{{-
'products.product.quantity.minimum_of'
| t: quantity: product.selected_or_first_available_variant.quantity_rule.min
-}}
</span>
{%- endif -%}
{%- if product.selected_or_first_available_variant.quantity_rule.max != null -%}
<span class="divider">
{{-
'products.product.quantity.maximum_of'
| t: quantity: product.selected_or_first_available_variant.quantity_rule.max
-}}
</span>
{%- endif -%}
</div>
{%- if product.quantity_price_breaks_configured? -%}
<volume-pricing class="parent-display" id="Volume-{{ section.id }}">
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size > 0 -%}
<span class="caption-large">{{ 'products.product.volume_pricing.title' | t }}</span>
<ul class="list-unstyled">
<li>
<span>{{ product.selected_or_first_available_variant.quantity_rule.min }}+</span>
{%- assign price = product.selected_or_first_available_variant.price
| money_with_currency
-%}
<span data-text="{{ 'products.product.volume_pricing.price_at_each' | t: price: variant_price }}">
{{- 'sections.quick_order_list.each' | t: money: price -}}
</span>
</li>
{%- for price_break in product.selected_or_first_available_variant.quantity_price_breaks -%}
{%- assign price_break_price = price_break.price | money_with_currency -%}
<li class="{%- if forloop.index >= 3 -%}show-more-item hidden{%- endif -%}">
<span>
{{- price_break.minimum_quantity -}}
<span aria-hidden="true">+</span></span
>
<span data-text="{{ 'products.product.volume_pricing.price_at_each' | t: price: price_break_price }}">
{{- 'sections.quick_order_list.each' | t: money: price_break_price -}}
</span>
</li>
{%- endfor -%}
</ul>
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size >= 3 -%}
<show-more-button>
<button
class="button-show-more link underlined-link"
id="Show-More-{{ section.id }}"
type="button"
>
<span class="label-show-more label-text"
><span aria-hidden="true">+ </span>{{ 'products.facets.show_more' | t }}
</span>
</button>
</show-more-button>
{%- endif -%}
{%- endif -%}
</volume-pricing>
{%- endif -%}
</div>
{% endif %}
You will find it here
I hope, it will help you
Thanks!
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024