Adding multiple metafield links for popup images on product page

I used the following to craete a Size Chart pop-up using metafields:

It’s awesome and works perfectly! However - I’d like to add a second pop-up for product information so I don’t have a wall of text on the product page. I tried tweaking that code to do that, but it doesn’t work (no pop-up image happens). I assume something in the code is blocking or copying that I don’t understand (I really don’t understand coding).

What I want is basically this: two metafields, one for the size chart and one for product info. I want them to pull up a file image as a popup - I don’t want to have to create pages. The product info and size chart are independent of each other. I’d like a line that says “Size Chart” that pops up the size chart when you click it (I have that now from using the video above), and another line right below that with “Product Information” that pops up the product info when you click it.

Anyone know how to adapt or change what I’ve done to do that? I’ve read through the metafields pages for Shopify and am still lost.

Hi @clotharmor ,

Please follow this steps :

Add this code where you want to display :

{% if product.description != blank %}
                <a id="btn-{{ product.id }}" class="pdpdes-button" href="#productdescription">Product Description</a>
              {% endif %}

Create new snippet called → product-description-popup.liquid and add below code in this snippet :

<style>
  .sizeguide-button {
    margin-left: auto;
    font-size: 1em;
    color: #000;
    cursor: pointer;
    transition: all 0.3s ease-out;
    text-decoration: underline;
  }
  .sizeguide-button:hover {
    /* text-decoration: none; */
  }
  #productdescription.overlay {
    position: fixed;
    z-index: 9;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    transition: opacity 500ms;
    visibility: hidden;
    opacity: 0;
  }
  #productdescription.overlay:target {
    visibility: visible;
    opacity: 1;
  }

  #productdescription .popup {
    margin: 70px auto;
    background: none;
    border-radius: 5px;
    width: 35%;
    position: relative;
    transition: all 5s ease-in-out;
  }
  #productdescription img {
    border-radius: 2px;
  }

  #productdescription .popup h2 {
    margin-top: 0;
    color: #333;
    font-family: Tahoma, Arial, sans-serif;
  }
  #productdescription .popup .close {
    position: absolute;
    display: inline;
    top: 4px;
    right: 19px;
    transition: all 200ms;
    font-size: 30px;
    font-weight: bold;
    text-decoration: none;
    color: #000;
  }
  #productdescription .popup .close:hover {
    color: #d9d2c9;
  }
  #productdescription .popup .content {
    background: #fff;
    overflow: auto;
    padding: 20px;
  }
  #productdescription table {
    width: -webkit-fill-available;
  }
  #productdescription table,
  #productdescription tr,
  #productdescription th,
  #productdescription td {
    border: 1px solid;
    border-collapse: collapse;
  }
  #productdescription tr,
  #productdescription th,
  #productdescription td {
    padding: 10px 20px;
  }

  #btn-7893103378606,
  #btn-7893106294958 {
    display: none;
  }
  @media screen and (max-width: 700px) {
    #productdescription .popup .close {
      top: -8px;
      right: 12px;
    }
    #productdescription .popup {
      width: 93%;
    }
  }
</style>


<div id="productdescription" class="overlay">
  <div class="popup">
    <a class="close" href="#">×</a>
    <div class="content">
      {{ product.description }}
    </div>
  </div>
</div>

Add this line just below the sizechart popup :

{% render ‘product-description-popup’ %}

Let me know if its work. If need any help please ask i will guide. Thank you

Thanks for your help! However, this would only give me a static product description. I want to use metafields like for the size chart so I can assign the correct jpg file with product info on the product page instead of having to reassign code to each one.

Hey @clotharmor,
This need to do the custom coding in your theme file. Could you please share the 4 digits collab code with me so that I can do the requested changes.
Thanks

Hey! I totally get what you’re trying to do and why the current solution isn’t working for you. You want the same popup functionality but using metafields for product info images just like you have for the size chart. Here’s how to modify the code to make it work:

Step 1: Create the metafields
First, you’ll need two metafields in your Shopify admin:

  • One for size chart (sounds like you already have this)
  • One for product info

Go to Settings > Metafields > Products and create:

  • Namespace: custom, Key: size_chart, Type: File
  • Namespace: custom, Key: product_info, Type: File

Step 2: Create a new snippet
Create a file called product-info-popup.liquid in your snippets folder and add this code:

{% if product.metafields.custom.product_info %}
<style>
  .productinfo-button {
    margin-left: auto;
    font-size: 1em;
    color: #000;
    cursor: pointer;
    transition: all 0.3s ease-out;
    text-decoration: underline;
    display: block;
    margin-bottom: 10px;
  }
  .productinfo-button:hover {
    color: #666;
  }
  
  #productinfo.overlay {
    position: fixed;
    z-index: 9999;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    transition: opacity 500ms;
    visibility: hidden;
    opacity: 0;
  }
  
  #productinfo.overlay:target {
    visibility: visible;
    opacity: 1;
  }

  #productinfo .popup {
    margin: 70px auto;
    background: #fff;
    border-radius: 5px;
    width: 80%;
    max-width: 600px;
    position: relative;
    transition: all 0.3s ease-in-out;
  }
  
  #productinfo .popup img {
    width: 100%;
    height: auto;
    border-radius: 2px;
  }

  #productinfo .popup .close {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 30px;
    height: 30px;
    background: #000;
    color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 30px;
    font-size: 20px;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
  }
  
  #productinfo .popup .close:hover {
    background: #666;
  }

  @media screen and (max-width: 700px) {
    #productinfo .popup {
      width: 95%;
      margin: 20px auto;
    }
  }
</style>

<a class="productinfo-button" href="#productinfo">Product Information</a>

<div id="productinfo" class="overlay">
  <div class="popup">
    <a class="close" href="#">×</a>
    <img src="{{ product.metafields.custom.product_info | img_url: 'master' }}" alt="Product Information">
  </div>
</div>
{% endif %}

Step 3: Update your existing size chart code
Make sure your size chart button and popup have unique IDs. Your size chart popup should use #sizechart and the product info should use #productinfo (different IDs so they don’t conflict).

Step 4: Add both snippets to your product template
In your product template file (usually product.liquid or product-form.liquid), add both snippets where you want the buttons to appear:

{% render 'size-chart-popup' %}
{% render 'product-info-popup' %}

Step 5: Upload your images
Go to each product in your admin, scroll down to metafields, and upload:

  • Your size chart image to the size_chart metafield
  • Your product info image to the product_info metafield

The key differences from what you tried before:

  1. Each popup has completely unique IDs (#sizechart vs #productinfo)
  2. Both use the same metafield structure you’re already familiar with
  3. The CSS is scoped to each specific popup so they don’t interfere with each other
  4. Each only shows if the metafield has content

This way you can assign different images to different products through metafields without having to mess with code for each product. Just upload the images in the admin and they’ll automatically show up with the popup functionality.

Let me know if you run into any issues with this setup!

Cheers!
Shubham | Untechnickle

Thanks for this - it isn’t working and seems to be missing some parts? At least judging from what I did previously to make the size chart popup work.