Hello, my shop is infinitycosmetics.it
I want to remove add to cart button under unavailable products, anyone can help me?
Currently there is the “out of stock” label, but customers can still add the product to the cart because the button is there. I would like to remove the button from out of stock products.
currently there is the “out of stock” label, but customers can still add the product to the cart because the button is there. I would like to remove the button from out of stock products.
ordinarily most of the theme will make this product unavailable for add to cart if it is out of stock, unless you have specifically ticked the option to “continue selling when out of stock”. Please check in your admin dashboard - go to the specific product, and under inventory section, do you have that ticked? If you untick it, the customer should not be able to buy / add to cart.
It is already unticked
I want to show unaivalable products but I don’t want to add to cart
What theme are you using? It is hard to guess whether the issue is with theme configuration or backend. But to be honest, I find it hard to believe any well designed theme would just keep selling even out of stock without giving user the ability to untick. If it is a custom theme, I would suggest to reach out to the theme developer.
Otherwise, can you please provide the liquid code so I can try to check? The add to cart component should be inside product.liquid.
You can add a liquid logic inside the code basically says something like below, but you kind of need to know where to add that. Basically find the add to cart button, and add the last few lines of code inside it.
<button
type="submit"
name="add"
{% if product.selected_or_first_available_variant.available == false %}
disabled
{% endif %}
>
I tryed but it doesn’t work.
THIS IS MY THEME.LIQUID CODE
{% unless request.path contains ‘/account’ %} {% assign restrict_page = true %} {% endunless %}
{% if shop.metafields.adv_reg.noFraming == ‘on’ %} {% assign restrict_page = true %}{% endif %}
{% if shop.metafields.adv_reg.useBlacklist == ‘on’ %}
{% assign restrict_page = false %}
{% assign blockPages = shop.metafields.adv_reg.blockPageUrls | split: “|” %}
{% for url in blockPages %}
{% if request.path == url %}{% assign restrict_page = true %} {% endif %}
{% endfor %}
{% else %}
{% assign exceptionUrls = shop.metafields.adv_reg.lockShopExceptionUrls | split: “|” %}
{% for url in exceptionUrls %}
{% if request.path == url %}{% assign restrict_page = false %} {% endif %}
{% endfor %}
{% endif %}
{% if request.path == ‘/challenge’ %} {% assign restrict_page = false %} {% endif %}
{% if request.path == ‘/password’ %} {% assign restrict_page = false %} {% endif %}
{% if request.path == ‘/account/recover’ %} {% assign restrict_page = false %} {% endif %}
{% if request.path contains ‘/tools/emails’ %} {% assign restrict_page = false %} {% endif %}
{% if request.path contains ‘/account/reset’ %} {% assign restrict_page = false %} {% endif %}
{% if request.path contains ‘/account/activate’ %} {% assign restrict_page = false %} {% endif %}
{% if request.path contains ‘/reset-password’ %} {% assign restrict_page = false %} {% endif %}
{% if request.path contains ‘/customer-account-password-reset’ %} {% assign restrict_page = false %} {% endif %}
{% if shop.metafields.adv_reg.lockShop == ‘on’ and customer == nil and restrict_page %}
{% if shop.metafields.adv_reg.noFraming == ‘on’ %}
{% include ‘advanced_registration_locked_page’ %}
{% else %}
{% render ‘judgeme_core’ %}
{% include "starapps-core" %}{%- render ‘layouthub_header’ -%}{% render ‘pagefly-head’ %}
{{page_title}} {% if page_description %} {% endif %} {% if shop.metafields.adv_reg.showRegistrationPageFirst == 'on' %} {% else %} {% endif %} {% render 'wsg-custom' %} {% endif %} {% else %} {% include "starapps-core" %}{%- render ‘layouthub_header’ -%}
{{ page_title }}{% if current_tags %}{% assign meta_tags = current_tags | join: ', ' %} – {{ 'general.meta.tags' | t: tags: meta_tags }}{% endif %}{% if current_page != 1 %} – {{ 'general.meta.page' | t: page: current_page }}{% endif %}{% unless page_title contains shop.name %} – {{ shop.name }}{% endunless %}{% if page_description %}
{% endif %}
{% if template contains ‘product’ %}
{% else %}
{% endif %}
{% render ‘social-meta-tags’ %}
{% render ‘css-variables’ %}
{{ ‘theme.min.css’ | asset_url | stylesheet_tag }}
{{ ‘custom.css’ | asset_url | stylesheet_tag }}
{% render ‘font-links’ %}
{% if settings.favicon != blank %}
{% endif %}{% render “starapps-product-json”, product: product, starapps_app: “VIA”, starapps_attribute: “sa-product-json” %}
{{ content_for_header }}
{% if template contains ‘customers’ %}
{{ “shopify_common.js” | shopify_asset_url | script_tag }}
{{ “customer_area.js” | shopify_asset_url | script_tag }}
{% endif %}
{% include ‘productwiz-rio’ %}
{% include ‘bss-product-labels-configs’ %}
{% render ‘wishlisthero-styles.liquid’ %}
{% render ‘wsg-custom’ %}
{% if template != ‘cart’ %}
{% render ‘cart-drawer’ %}
{% endif %}
{% section ‘announcement-bar’ %}
{% section ‘header’ %}
{% unless template == “index” or template == “collection” %}
{% include ‘station-tabs’ %}
{% unless template == “index” or template == “collection” %}
{% section ‘footer’ %}
{% render ‘popup’ %}
{% include ‘productpageswatchsnippet’ %}{% include ‘swatchyappvariables’ %}{% include ‘social-login’ %}{{ ‘ndnapps-sociallogin.css’ | asset_url | stylesheet_tag }}
{% if shop.customer_accounts_enabled %}{% unless customer %}{{ ‘ndnapps-sociallogin-script.js’ | asset_url | script_tag }}{% endunless %}{% endif %}
{% include ‘pointkit_snippet’ %}
{% comment %} sc_discountbox include {% endcomment %}
{% include ‘sc-discount-app’ %}
{% comment %} end of sc_discountbox include {% endcomment %}
{% render ‘spurit_wsmm-theme-snippet’ %}
{% if customer.tags.size > 0 and template != ‘cart’ %}
{% endif %}
{% if customer.tags.size > 0 and template == ‘cart’ %}
{% include ‘wcp_cart’ %}
{% endif %}
{%- render ‘layouthub_footer’ -%}
{% render ‘spurit_dmr_theme_snippet’ %}
ENVY THEME, and this is my TEMPLATE–PRODUCT.LIQUID CODE
{% unless product.tags contains “gift_product” %}
{%- assign product_thumb_size = ‘160x160’ -%}
{%- assign product_image_zoom_size = ‘1024x1024’ -%}
{% comment %}Pick an option only makes sense together with dropdowns{% endcomment %}
{% if settings.show_swatches == false and section.settings.pick_an_option %}
{% assign pick_an_option = true %}
{% else %}
{% assign pick_an_option = false %}
{% endif %}
{% if pick_an_option %}
{%- assign current_variant = product.selected_variant -%}
{% else %}
{%- assign current_variant = product.selected_or_first_available_variant -%}
{% endif %}
{%- assign featured_image = current_variant.featured_image | default: product.featured_image -%}
{% comment %}
Check if the product is on sale and set a variable to be used below.
{% endcomment %}
{% assign on_sale = false %}
{% if current_variant.compare_at_price > current_variant.price %}
{% assign on_sale = true %}
{% endif %}
{% assign full_width = false %}
{% if section.settings.image_size == ‘full-width’ %}
{% assign full_width = true %}
{% endif %}
{% case section.settings.image_size %}
{% when ‘small’ %}
{%- assign product_image_width = 6 -%}
{%- assign product_image_size = ‘345x’ -%}
{% when ‘medium’ %}
{%- assign product_image_width = 7 -%}
{%- assign product_image_size = ‘530x’ -%}
{% when ‘large’ %}
{%- assign product_image_width = 8 -%}
{%- assign product_image_size = ‘720x’ -%}
{% when ‘full-width’ %}
{%- assign product_image_width = 12 -%}
{%- assign product_image_size = ‘900x’ -%}
{% endcase %}
{% if section.settings.thumbnail_position == ‘below’ or product.images.size <= 1 %}
{% case section.settings.image_size %}
{% when ‘small’ %}
{%- assign product_description_width = ‘col-md-6’ -%}
{% when ‘medium’ %}
{%- assign product_description_width = ‘col-md-5’ -%}
{% when ‘large’ %}
{%- assign product_description_width = ‘col-md-4’ -%}
{% when ‘full-width’ %}
{%- assign product_description_width = ‘col-md-12’ -%}
{% endcase %}
{% else %}
{% case section.settings.image_size %}
{% when ‘small’ %}
{%- assign product_description_width = ‘col-md-5’ -%}
{% when ‘medium’ %}
{%- assign product_description_width = ‘col-md-4’ -%}
{% when ‘large’ %}
{%- assign product_description_width = ‘col-md-3’ -%}
{% when ‘full-width’ %}
{%- assign product_description_width = ‘col-md-12’ -%}
{% endcase %}
{% endif %}
{% if collection %}
›
{% if collection.handle %}
{% capture url %}/collections/{{ collection.handle }}{% endcapture %}
{{ collection.title | link_to: url }}
{% endif %}
{% endif %}
›
{{ product.title }}
{% capture thumbnails %}
{% if settings.sale_badge %}
{% if section.settings.thumbnail_position == ‘below’ %}
{{ thumbnails }}
{% endif %}
{% capture out_of_stock_email_form %}
{{ 'products.product.thanks' | t }}
{% if form.posted_successfully? %} .stock-notice{ display:none; } {% else %} {{ 'products.product.out-stock_html' | t: product: product.title }} {% endif %} {% if form.errors %}{% if full_width %}
{% if section.settings.description_position == “below” %}
{% if full_width %}
{% if full_width %}
{% if full_width %}
{% if product.available %}
{% form ‘product’, product, id: “add-to-cart-form” %}
{% render ‘unit-price-measurement-variant’, variant: current_variant %}
{% unless section.settings.show_discount == ‘hide’ %}
{% assign hide_default_title = false %}
{% if product.variants.size == 1 and product.variants.first.title contains ‘Default’ %}
{% assign hide_default_title = true %}
{% endif %}
{% if settings.show_swatches %}
{% if product.variants.size > 1 %}
{% for option in product.options %}
{% render ‘swatch’ with option, product: product, section: section %}
{% endfor %}
{% endif %}
{% else %}
{% for option in product.options_with_values %}
{% endif %}
{% endif %}
{% if section.settings.show_quantity_selector %}
{% if section.settings.show_smart_checkout %}
{{ form | payment_button }}
{% endif %}
{% if section.settings.show_out_of_stock_email %}
{% else %}
{{ 'products.product.sorry_stock' | t }}
{% if section.settings.show_out_of_stock_email %} {{ out_of_stock_email_form }} {% endif %}{% endif %}
{% if full_width %}
{% if section.settings.description_position == “above” %}
{% if full_width %}
{% if full_width %}
{% endif %}
{% if full_width %}
{% if full_width %}
{% unless product.empty? %}
{% endunless %}
The problem is in the collections page, in product pages is ok.
You can’t add this to the theme code, that is not where it should be added.
Looks like you are using the Envy theme, is it the Envy 2.0? Their support should be able to help you if you need help on theme.
If you are using 2.0, then go to Edit Code → Snippets → card-product.liquid, and find:
{%- if show_quick_add -%}
And then find . The following code should resemble something like this. It might have a different class name or some sorts, as i don’t know the liquid code inside Envy. But again the important bit is the if logic. If you don’t know what you need to do, find the relevant line in your liquid file, and paste in the thread so I can see it.
<button
id="{{ product_form_id }}-submit"
type="submit"
name="add"
class="quick-add__submit button button--full-width button--secondary"
aria-haspopup="dialog"
aria-labelledby="{{ product_form_id }}-submit title-{{ section_id }}-{{ card_product.id }}"
aria-live="polite"
data-sold-out-message="true"
**{% if card_product.selected_or_first_available_variant.available == false %}**
**disabled**
**{% endif %}**
>
My theme is ENVY version 26.3.0 and I can’t find card-product.liquid
Oh, you are not on the 2.0 themes. The shopify 2.0 themes are structured differently.
Can you see this?
Edit Code → Snippet → product-grid-item.liquid?
Can you please copy and paste the code from that file in this thread? I assume the theme has some customisation there to enable the add to cart.
I see product-grid–indiv-product.liquid and product-grid–onboarding-product.liquid
Can you copy and paste the code for both files? It is hard to gauge which one, as both seem to be bespoke to the theme itself.
Alternatively, if you had bought the theme, you really should reach out to the theme developer via the shopify theme store, they should be able to help you much faster.
Yes, I found my Add to cart button in product-grid–indiv-product.liquid file, this is the code:
{% assign crop_setting = settings.product-grid %}
{% if crop_setting == “square” %}
{% assign image_crop = “aspect-ratio–square” %}
{% elsif crop_setting == “tall” %}
{% assign image_crop = “aspect-ratio–tall” %}
{% elsif crop_setting == “wide” %}
{% assign image_crop = “aspect-ratio–wide” %}
{% endif %}
{% case settings.hover-effect %}
{% when ‘none’ %}
{% if image_crop %}{% when ‘second-image’ %}
{% if liquidObject.media.size > 1 %}
{% else %} {% if image_crop %}{% when ‘zoom’ %}
{{ }}
{% endcase %}
{% if settings.show_vendor %}
{{ liquidObject.title }}
{% if liquidObject.compare_at_price_max > liquidObject.price %}
{{ liquidObject.compare_at_price_max | money }}
{% endif %}
{% if liquidObject.price_varies %}
{{ ‘products.general.from’ | t }} {{ liquidObject.price_min | money }}
{% else %}
{{ liquidObject.price_min | money }}
{% endif %}
{% assign first_variant = liquidObject.variants[0] %}
{% render ‘unit-price-measurement-grid’, variant: first_variant %}
{% if settings.show_reviews %}
{% endif %}
{% if settings.show_swatches %}
{% for option in liquidObject.options %}
{% capture downcased_option %}{{ option | downcase }}{% endcapture %}
{% assign option_handle = option | handle %}
{% assign option_index = forloop.index0 %}
{% assign prod_id = liquidObject.id %}
{% if downcased_option contains ‘color’ or downcased_option contains ‘colour’ %}
{% if product.variants.size > 1 %}
{% assign values = ‘’ %}
{% for variant in product.variants %}
{% assign variantID = variant.id %}
{% assign value = variant.options[option_index] %}
{% capture wrapped_value %},{{ value }},{% endcapture %}
{% unless values contains wrapped_value %}
{% if variant.image %}
{% assign image = variant.image | product_img_url: ‘400x’ %}
{% else %}
{% assign image = liquidObject.media[0].preview_image | product_img_url: ‘400x’ %}
{% endif %}
{% capture values %}{{ values }}{{ wrapped_value }}{% endcapture %}
{% endunless %}
{% endfor %}
{% endfor %}
{% endif %}
{% if liquidObject.available %}
{% if liquidObject.compare_at_price_max > liquidObject.price and settings.sale_badge %}
Let’s try this, I can’t debug so I don’t know for sure, but I think this should work. If you replace the last 4 lines of your code with the following:
<form method="post" action="/cart/add" align="center">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input type="submit" value="Aggiungi al carrello" class="btn" {% if product.selected_or_first_available_variant.available == false %}
disabled{% endif %}/>
</form>
Thanks a lot, you are the best!!
great, I am glad we got there finally!
off sitewide
July sale — 45% off at checkout, applied automatically. Valid for 60 minutes. One per customer.
Offer ends in