Re: Add "Available Now" text to products in grid like "sold out". Pipeline theme

Solved

Add "Available Now" text to products in grid like "sold out". Pipeline theme.

Redroot_Blades
Excursionist
23 3 5

Hello, 

 

I had this figured out before the last big update...Now it doesn't work. 

 

I'm looking to have each product either say "Available Now" or "Sold out" under their price in the product grid. Currently the products that are available say nothing. 

 

https://www.redrootblades.com/collections/outdoor-knives has one available item, so you can see what I mean. 

 

Any help would be grand. Thanks! 

Accepted Solutions (2)

Redroot_Blades
Excursionist
23 3 5

This is an accepted solution.

Thank you! Here is the code below. I see the elements to edit, I just don't know the language. 

 


{% comment %}
A grid item for products used in collection grid view

* product {object} - The current prodcut

{% render 'product-grid-item', product: product %}
{% endcomment %}

{%- liquid
assign current_variant = product.first_available_variant

assign on_sale = false
if product.compare_at_price > product.price
assign on_sale = true
endif

assign sold_out = true
if product.available
assign sold_out = false
endif

assign sold_out = true
if product.available
assign sold_out = false
endif



assign sellout_badge = false
if sold_out and settings.badge_sellout
assign sellout_badge = true
endif

assign sale_badge = false
if on_sale and settings.badge_sale
assign sale_badge = true
assign sale_badge_content = 'products.product.sale' | t
if settings.badge_sale_discount
if settings.badge_sale_type == 'dollar'
assign sale_badge_content = product.compare_at_price | minus: product.price | money_without_trailing_zeros
else
assign difference = product.compare_at_price | minus: product.price
assign percent_off = difference | times: 1.0 | divided_by: product.compare_at_price | times: 100
assign sale_badge_content = percent_off | floor | append: '%'
endif
assign save_word = 'products.product.save' | t | append: ' '
assign sale_badge_content = sale_badge_content | prepend: save_word
endif
endif

assign custom_badge = false
if settings.badge_custom
for tag in product.tags
if tag contains "_badge_"
assign custom_badge = true
assign custom_badge_content = tag | remove: '_badge_' | replace: '_', ' '
break
endif
endfor
endif

assign setting_badge = false
if badge_string and badge_string != ''
assign setting_badge = true
endif

assign tagged = false
if sellout_badge or sale_badge or custom_badge or setting_badge
assign tagged = true
endif
-%}
{%- capture badge -%}
{%- if tagged %}
{%- if setting_badge -%}
<div class="product__badge product__badge--setting">{{ badge_string }}</div>
{%- elsif custom_badge -%}
<div class="product__badge product__badge--custom">{{ custom_badge_content }}</div>
{%- elsif sellout_badge -%}
<div class="product__badge product__badge--sold">{{ 'products.product.sold_out' | t }}</div>
{%- elsif sale_badge -%}
<div class="product__badge product__badge--sale">{{ sale_badge_content }}</div>
{%- endif -%}
{%- endif -%}
{%- endcapture -%}


{%- capture swatches -%}
{%- if settings.swatches_enable and settings.swatches_collection_enable -%}
{%- capture swatch_translation -%}{{ 'general.swatches.color' | t }}{%- endcapture -%}
{%- assign swatch_labels = swatch_translation | append: ',' | split: ',' -%}
{%- for label in swatch_labels -%}
{%- assign sanitized_label = label | lstrip | rstrip -%}
{%- if product.options_by_name[sanitized_label].values.size > 0 -%}
<div class="grid__swatch__container">
<p class="grid__swatch__placeholder">{{ 'collections.general.swatches_with_count' | t: count: product.options_by_name[sanitized_label].values.size }}</p>
<form class="grid__swatch__hover" data-grid-swatches data-swatch-handle="{{ product.handle }}" data-swatch-label="{{ label }}"></form>
</div>
{% break %}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endcapture -%}

{%- liquid
assign double_img = false
if product.media[1].preview_image and settings.image_hover_enable
assign double_img = true
endif

assign product_img_ratio = product.featured_media.preview_image.aspect_ratio | default: 1
assign image_ratio = 1 | divided_by: product_img_ratio | times: 100
if settings.product_grid_image == 'crop'
assign image_ratio = settings.product_grid_aspect_ratio | times: 100
elsif settings.product_grid_image == 'scale'
assign multiplier = settings.product_grid_aspect_ratio
assign inverse_ratio = 1 | divided_by: product_img_ratio
assign top_offset = 1 | divided_by: product_img_ratio | times: 100 | divided_by: 2
assign top_offset_subtractor = multiplier | times: 100 | divided_by: 2
endif
-%}

{%- if settings.product_grid_image == 'scale' -%}
{%- capture auto_height -%}
{%- if inverse_ratio > multiplier -%}
style="width:{{ product_img_ratio | times: multiplier | times: 100 }}%; margin: 0 auto;"
{%- else -%}
style="padding:{{ top_offset_subtractor | minus: top_offset }}% 0;"
{%- endif -%}
{%- endcapture -%}
{%- endif -%}


<div class="product-grid-item {{ image_classes }}{% if on_sale %} on-sale{% endif %}{% if tagged %} tagged{% endif %}" data-grid-item>
<div {{ auto_height }}>
<a href="{{ product.url | within: collection }}" data-grid-link class="lazy-image{% if double_img %} double__image{% endif %}" aria-label="{{ product.title | strip_html | escape }}" style="padding-top:{{ image_ratio }}%; background-image: url('{{ product.featured_media.preview_image | img_url: '1x1' }}');">
<div class="lazyload fade-in collection__image__top"
data-bgset="{% render 'bgset', image: product.featured_media.preview_image %}"
role="img"
aria-label="{{ product.featured_media.alt | default: product.title | strip_html | escape }}"></div>
{% if double_img %}
<div class="collection__image__bottom">
{%- assign img_url = product.media[1].preview_image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
<img data-src="{{ img_url }}"
class="lazyload img-object-cover lazypostload-desktop"
width="{{ product.media[1].preview_image.width }}"
height="{{ product.media[1].preview_image.height }}"
data-widths="[110, 160, 220, 320, 480, 540, 720, 900]"
data-sizes="auto"
data-aspectratio="{{ product.media[1].preview_image.aspect_ratio }}"
alt="{{ product.media[1].alt | strip_html | escape }}">
</div>
{% endif %}
<div class="product-grid-item__slide" data-grid-slide></div>
{{ badge }}
</a>
</div>
<noscript>
<a href="{{ product.url | within: collection }}">
<img class="responsive-wide-image" src="{{ product.featured_media.preview_image | img_url: '360x' }}" alt="{{ product.featured_media.alt | default: product.title | strip_html | escape }}">
{{ badge }}
</a>
</noscript>
<div class="product__grid__info product__grid__info--{{ settings.product_grid_style }} {{ text_align | default: settings.collection_text_alignment | default: 'text-center' }}">
<a href="{{ product.url | within: collection | capitalize }}">
<div class="product__grid__title__wrapper">
<p class="product__grid__title">
{{ product.title }}
</p>
{%- if settings.product_grid_show_rating and product.metafields.reviews.rating.value != blank -%}
<div class="rating__wrapper__grid">
{% render 'product-rating', product: product, show_rating_count: settings.product_grid_show_rating_count %}
</div>
{%- endif -%}
</div>
<div class="product__grid__price">
<span class="price{% if on_sale %} on-sale{% endif %}">
{% if product.price_varies %}{{ 'products.general.from' | t }} {% endif %}
{{ product.price | money }}
</span>
{% if on_sale %}
<span class="compare-at">
{{ product.compare_at_price | money }}
</span>
{% endif %}
{% if current_variant.unit_price %}
{% capture unit_price_separator %}
<span aria-hidden="true">/</span><span class="visually-hidden">{{ 'general.accessibility.unit_price_separator' | t }}&nbsp;</span>
{% endcapture %}
{% capture unit_price_base_unit %}
{% if current_variant.unit_price_measurement.reference_value != 1 %}
{{ current_variant.unit_price_measurement.reference_value }}
{% endif %}
{{ current_variant.unit_price_measurement.reference_unit }}
{% endcapture %}
<br>
<span class="visually-hidden">{{ 'products.product.unit_price_label' | t }}</span>
<span class="price-per-unit">{{ current_variant.unit_price | money }}{{ unit_price_separator }}{{ unit_price_base_unit }}</span>
{% endif %}
{% if sold_out %}
<br /><em>{{ 'products.product.sold_out' | t }}</em>
{% endif %}
{{ swatches }}
</div>
</a>
</div>
</div>

View solution in original post

Redroot_Blades
Excursionist
23 3 5

This is an accepted solution.

I figured it out. I added the following to the correct spot in product-grid-item.liquid :

 

<br>
{% if product.available %}
Available Now
{% endif %}
<br />

 

View solution in original post

Replies 4 (4)

Ahsan_ANC
Shopify Partner
1410 254 328

Hi @Redroot_Blades please share the code of this section. It should look like a product grid item in your theme editor snippets folder.

Contact for any custom design? Skype : ahsananc
>Was your question answered? Mark it as an Accepted Solution!
Feel Free to Contact Me at my Email: anc2277@gmail.com


To enhance and customize Shopify search and filter, I use Boost Product Filter & Search

suyash1
Shopify Partner
10862 1343 1718

@Redroot_Blades - this will need code editing, it can be one.

To build shopify pages use PAGEFLY | Contact me - suyash.patankar@gmail.com , My timezone is GMT+5:30.

Redroot_Blades
Excursionist
23 3 5

This is an accepted solution.

Thank you! Here is the code below. I see the elements to edit, I just don't know the language. 

 


{% comment %}
A grid item for products used in collection grid view

* product {object} - The current prodcut

{% render 'product-grid-item', product: product %}
{% endcomment %}

{%- liquid
assign current_variant = product.first_available_variant

assign on_sale = false
if product.compare_at_price > product.price
assign on_sale = true
endif

assign sold_out = true
if product.available
assign sold_out = false
endif

assign sold_out = true
if product.available
assign sold_out = false
endif



assign sellout_badge = false
if sold_out and settings.badge_sellout
assign sellout_badge = true
endif

assign sale_badge = false
if on_sale and settings.badge_sale
assign sale_badge = true
assign sale_badge_content = 'products.product.sale' | t
if settings.badge_sale_discount
if settings.badge_sale_type == 'dollar'
assign sale_badge_content = product.compare_at_price | minus: product.price | money_without_trailing_zeros
else
assign difference = product.compare_at_price | minus: product.price
assign percent_off = difference | times: 1.0 | divided_by: product.compare_at_price | times: 100
assign sale_badge_content = percent_off | floor | append: '%'
endif
assign save_word = 'products.product.save' | t | append: ' '
assign sale_badge_content = sale_badge_content | prepend: save_word
endif
endif

assign custom_badge = false
if settings.badge_custom
for tag in product.tags
if tag contains "_badge_"
assign custom_badge = true
assign custom_badge_content = tag | remove: '_badge_' | replace: '_', ' '
break
endif
endfor
endif

assign setting_badge = false
if badge_string and badge_string != ''
assign setting_badge = true
endif

assign tagged = false
if sellout_badge or sale_badge or custom_badge or setting_badge
assign tagged = true
endif
-%}
{%- capture badge -%}
{%- if tagged %}
{%- if setting_badge -%}
<div class="product__badge product__badge--setting">{{ badge_string }}</div>
{%- elsif custom_badge -%}
<div class="product__badge product__badge--custom">{{ custom_badge_content }}</div>
{%- elsif sellout_badge -%}
<div class="product__badge product__badge--sold">{{ 'products.product.sold_out' | t }}</div>
{%- elsif sale_badge -%}
<div class="product__badge product__badge--sale">{{ sale_badge_content }}</div>
{%- endif -%}
{%- endif -%}
{%- endcapture -%}


{%- capture swatches -%}
{%- if settings.swatches_enable and settings.swatches_collection_enable -%}
{%- capture swatch_translation -%}{{ 'general.swatches.color' | t }}{%- endcapture -%}
{%- assign swatch_labels = swatch_translation | append: ',' | split: ',' -%}
{%- for label in swatch_labels -%}
{%- assign sanitized_label = label | lstrip | rstrip -%}
{%- if product.options_by_name[sanitized_label].values.size > 0 -%}
<div class="grid__swatch__container">
<p class="grid__swatch__placeholder">{{ 'collections.general.swatches_with_count' | t: count: product.options_by_name[sanitized_label].values.size }}</p>
<form class="grid__swatch__hover" data-grid-swatches data-swatch-handle="{{ product.handle }}" data-swatch-label="{{ label }}"></form>
</div>
{% break %}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endcapture -%}

{%- liquid
assign double_img = false
if product.media[1].preview_image and settings.image_hover_enable
assign double_img = true
endif

assign product_img_ratio = product.featured_media.preview_image.aspect_ratio | default: 1
assign image_ratio = 1 | divided_by: product_img_ratio | times: 100
if settings.product_grid_image == 'crop'
assign image_ratio = settings.product_grid_aspect_ratio | times: 100
elsif settings.product_grid_image == 'scale'
assign multiplier = settings.product_grid_aspect_ratio
assign inverse_ratio = 1 | divided_by: product_img_ratio
assign top_offset = 1 | divided_by: product_img_ratio | times: 100 | divided_by: 2
assign top_offset_subtractor = multiplier | times: 100 | divided_by: 2
endif
-%}

{%- if settings.product_grid_image == 'scale' -%}
{%- capture auto_height -%}
{%- if inverse_ratio > multiplier -%}
style="width:{{ product_img_ratio | times: multiplier | times: 100 }}%; margin: 0 auto;"
{%- else -%}
style="padding:{{ top_offset_subtractor | minus: top_offset }}% 0;"
{%- endif -%}
{%- endcapture -%}
{%- endif -%}


<div class="product-grid-item {{ image_classes }}{% if on_sale %} on-sale{% endif %}{% if tagged %} tagged{% endif %}" data-grid-item>
<div {{ auto_height }}>
<a href="{{ product.url | within: collection }}" data-grid-link class="lazy-image{% if double_img %} double__image{% endif %}" aria-label="{{ product.title | strip_html | escape }}" style="padding-top:{{ image_ratio }}%; background-image: url('{{ product.featured_media.preview_image | img_url: '1x1' }}');">
<div class="lazyload fade-in collection__image__top"
data-bgset="{% render 'bgset', image: product.featured_media.preview_image %}"
role="img"
aria-label="{{ product.featured_media.alt | default: product.title | strip_html | escape }}"></div>
{% if double_img %}
<div class="collection__image__bottom">
{%- assign img_url = product.media[1].preview_image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}
<img data-src="{{ img_url }}"
class="lazyload img-object-cover lazypostload-desktop"
width="{{ product.media[1].preview_image.width }}"
height="{{ product.media[1].preview_image.height }}"
data-widths="[110, 160, 220, 320, 480, 540, 720, 900]"
data-sizes="auto"
data-aspectratio="{{ product.media[1].preview_image.aspect_ratio }}"
alt="{{ product.media[1].alt | strip_html | escape }}">
</div>
{% endif %}
<div class="product-grid-item__slide" data-grid-slide></div>
{{ badge }}
</a>
</div>
<noscript>
<a href="{{ product.url | within: collection }}">
<img class="responsive-wide-image" src="{{ product.featured_media.preview_image | img_url: '360x' }}" alt="{{ product.featured_media.alt | default: product.title | strip_html | escape }}">
{{ badge }}
</a>
</noscript>
<div class="product__grid__info product__grid__info--{{ settings.product_grid_style }} {{ text_align | default: settings.collection_text_alignment | default: 'text-center' }}">
<a href="{{ product.url | within: collection | capitalize }}">
<div class="product__grid__title__wrapper">
<p class="product__grid__title">
{{ product.title }}
</p>
{%- if settings.product_grid_show_rating and product.metafields.reviews.rating.value != blank -%}
<div class="rating__wrapper__grid">
{% render 'product-rating', product: product, show_rating_count: settings.product_grid_show_rating_count %}
</div>
{%- endif -%}
</div>
<div class="product__grid__price">
<span class="price{% if on_sale %} on-sale{% endif %}">
{% if product.price_varies %}{{ 'products.general.from' | t }} {% endif %}
{{ product.price | money }}
</span>
{% if on_sale %}
<span class="compare-at">
{{ product.compare_at_price | money }}
</span>
{% endif %}
{% if current_variant.unit_price %}
{% capture unit_price_separator %}
<span aria-hidden="true">/</span><span class="visually-hidden">{{ 'general.accessibility.unit_price_separator' | t }}&nbsp;</span>
{% endcapture %}
{% capture unit_price_base_unit %}
{% if current_variant.unit_price_measurement.reference_value != 1 %}
{{ current_variant.unit_price_measurement.reference_value }}
{% endif %}
{{ current_variant.unit_price_measurement.reference_unit }}
{% endcapture %}
<br>
<span class="visually-hidden">{{ 'products.product.unit_price_label' | t }}</span>
<span class="price-per-unit">{{ current_variant.unit_price | money }}{{ unit_price_separator }}{{ unit_price_base_unit }}</span>
{% endif %}
{% if sold_out %}
<br /><em>{{ 'products.product.sold_out' | t }}</em>
{% endif %}
{{ swatches }}
</div>
</a>
</div>
</div>

Redroot_Blades
Excursionist
23 3 5

This is an accepted solution.

I figured it out. I added the following to the correct spot in product-grid-item.liquid :

 

<br>
{% if product.available %}
Available Now
{% endif %}
<br />