Show a product with variants on homepage

Ajay08
Tourist
10 0 1

provide me sample code to show a product with variants on homepage in Shopify

Reply 1 (1)
Jasoliya
Shopify Expert
4753 617 1199

It must be theme based different but you can try this 

Or you can also use feature product section on home page which is available in all theme 

but you can use custom code like this, try to add this code in custom liquid section 

//you can assing product hande here that you want to disply on home page 
{% assign pro_handle = 'your-product-handle' %}
{% assign product = all_products[pro_handle] %}

{% if product %}
  <h1>{{ product.title }}</h1>
  
  <select id="product-variants">
    {% for variant in product.variants %}
      <option value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money }}</option>
    {% endfor %}
  </select>
  
  <button id="add-to-cart" class="btn" >Add to Cart</button>
  
// this is Js code to manage variant callback
  <script>
    var productData = {
      product: {{ product | json }},
      variants: {{ product.variants | json }}
    };
  
    // here you have to code for variants management like add to cart change image , price etc .
  </script>
  
{% endif %}

 

Want custom changes? hire me.
3 months of Shopify are available for $1/month. Look here.
Email us Or WhatsApp, Try our Free app for product bundles.
Want to get Free review and advice for sale on store ?? just text me here