Re: Using metafield to define a badge on Product grid in collection

Solved

Using metafield to define a badge on Product grid in collection

clavilla57
Explorer
92 0 16

Hey all, with sense 12.0.0 i'm trying to figured out how to add a badge that display the number 48, on product grid in collection

All by using metafield

 

https://bv8ko0rghwg57o7l-57179668671.shopifypreview.com

Accepted Solution (1)
Dan-From-Ryviu
Shopify Partner
9695 1938 1973

This is an accepted solution.

My mistake, please update code

{% assign badgeNumber = card_product.metafields.global.badge_number %}
    {% if badgeNumber == 48 %}
      <div class="badge">{{ badgeNumber }}</div>
    {% endif %}

 

- Helpful? Like and Accept solution! Support me! Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

View solution in original post

Replies 10 (10)

Huptech-Web
Shopify Partner
941 188 197

Hello @clavilla57 ,

 

You can create a product meta field for the badge and add conditions to display the badge on the product grid.

 

Example:  Create a Product Metafield:  product.metafields.custom.badge

add a condition in the product grid:

{% if product.metafields.custom.badge != blank %}
  {{ product.metafields.custom.badge }}
{% endif %}

 

If you found this response helpful, please do like and accept the solution. Thanks!
Need support with Customizing your Shopify store?
Feel free to contact me at info@huptechweb.com or Visit our website Huptech Web.
Instant Shortcode Builder: Integrate customizable UI features anywhere in your store - No coding knowledge required
clavilla57
Explorer
92 0 16

where i had to put this condition?

Dan-From-Ryviu
Shopify Partner
9695 1938 1973

Step 1: Create a Metafield

  1. Go to your Shopify admin.

  2. Click on "Settings" and then "Custom data."

  3. Click on "Products."

  4. Under "Product details," click "Add definition" to create a new Metafield definition.

    • Name: Enter a name like "Badge Number."
    • Namespace: You can use your store name or create a custom namespace.
    • Key: Enter a unique identifier like "badge_number."
    • Type: Choose "Integer" since you want to store a number.
    • Description: Add any relevant information.
  5. Save your Metafield definition.

Step 2: Add Metafield Values to Products

  1. Go to the product in your Shopify admin.
  2. Scroll down to the "Metafields" section.
  3. Enter the value "48" for the "Badge Number" Metafield.

Step 3: Modify Your Theme Files

  1. Locate the file responsible for displaying the product grid in your theme: card-product.liquid
  2. Within the loop that displays each product, retrieve the Metafield value and display the badge if it's set to 48, add this code below where you want to it appear 

 

 

    {% assign badgeNumber = product.metafields.global.badge_number %}
    {% if badgeNumber == 48 %}
      <div class="badge">{{ badgeNumber }}</div>
    {% endif %}

 

 

 

- Helpful? Like and Accept solution! Support me! Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

clavilla57
Explorer
92 0 16

how do i recognize where to put

 

{% assign badgeNumber = product.metafields.custom.badge_number %}
{% if badgeNumber == 48 %}
<div class="badge">{{ badgeNumber }}</div>
{% endif %}

 

Dan-From-Ryviu
Shopify Partner
9695 1938 1973

Where place do you want to add this badge? 

- Helpful? Like and Accept solution! Support me! Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

clavilla57
Explorer
92 0 16

Collection page. over the product image to indicate that product have "48 Capsules" pack

Dan-From-Ryviu
Shopify Partner
9695 1938 1973

Please go to your card-product.liquid file, go to line 123, add code above this line of code 

{%- if card_product.available == false -%}

 

 

- Helpful? Like and Accept solution! Support me! Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

clavilla57
Explorer
92 0 16

I'm not able to make it work

Immagine (2).png

Immagine1.png

  

Dan-From-Ryviu
Shopify Partner
9695 1938 1973

This is an accepted solution.

My mistake, please update code

{% assign badgeNumber = card_product.metafields.global.badge_number %}
    {% if badgeNumber == 48 %}
      <div class="badge">{{ badgeNumber }}</div>
    {% endif %}

 

- Helpful? Like and Accept solution! Support me! Buy me coffee
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Ryviu: Aliexpress Reviews - AliExpress Reviews Importer, one-click import aliexpress reviews, export reviews to CSV file.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.

clavilla57
Explorer
92 0 16