Liquid, JavaScript, themes, sales channels
Hello Community,
I need to add some optional hardware to two of my products. It's a set of bolts for for a couple bucks. I'd like to add a little checkbox and an image.
Does anyone know the liquid code for this?
Since it just for two items, I don't want to get an App that I need to pay a monthly fee on it.
Thanks, Diego
Hey,
what about using variants for those two products?
When your theme supports variant, that should be the easiest way.
Hello,
Without apps this is unfortunately impossible.
What is possible is having custom options without charging extra (using line variants), but if you wanna charge for the options then you'll have to use an app.
Kind regards,
Diego
To clarify, you want to add additional products to cart if a user has those products checked upon clicking 'add to cart'? If so you don't need an app for that. What's your site (& password if needed).
@NAVEKI Yes, exactly.
I was thinking there must be simple way to add a checkbox option that refers to the product id of the add-on item.
What do you suggest? I'm using the Debut Theme
@ogeid
If you want to add another product then it's possible without an app.
What wouldn't be possible is to add an extra option and charge for it.
You'd very likely need to have an AJAX cart on your store for this to work, I am not sure whether it'd work without it (I could be wrong though).
Ok, so the workflow would basically be:
1. Create a HTML checkbox input on your product-template.liquid
2. Listen for ATC clicks at theme.js
3. If the checkbox is ticked, add both the current product (plus its quantity) & the other product (plus the quantity of the main product).
I'd go even further and also add a field at the customize page to choose which product to add as an add-on.
Something like this:
Using something like cartJS would potentially make it easier as well.
Kind regards,
Diego
I was able to find a very simple code solution that seems to be working. I placed it below the product description with an Add-to-Cart button. The value number in the for input field is the add-on product variant id.
<div class="product-single__description rte">
{{ product.description }}
<br/> <br/>
<div class=add-on-product-style>
{% for tag in product.tags %}
{% if tag == 'add-on-anchor' %}
<form method="post" action="/cart/add">
<input type="hidden" name="id" value="35639764123804" />
<input type="hidden" value="4" id="quantity" name="quantity" />
Optional Anchor Bolt Set +$16.00
<input type="submit" value="Add to cart" class="btn" />
<input type="hidden" name="return_to" value="back" />
</form>
{% endif %}
{% endfor %}
</div>
</div>
This is how it looks on the product page. I still need to add some styling, but this is without any styling:
The add-on shows in the cart just like any other product:
I'll keep searching if I can find a way to do it with a checkbox.
have you found a solution with the checkboxes you wanted?
Yes, I was actually able to get a checkbox to work.
I first did a version that used the "tags" to identify the add-ons, which doesn't require any apps, but then decided to use a metafields instead. I installed Metafields Guru app which is free (for now).
Basically, I just needed something to identify which products should feature an add-on and which add-on.
In the metafields for the product, I list the SKU of the add-ons
In the product-template.liquid change/add the following:
1. add brackets to the id:
<select name="id[]" id="ProductSelect-{{ section.id }}" class="product-form__variants no-js">
This will allow you to add multiple products with the Add to Cart button.
2. Add the following code before {% endfrom %}
<! -- Add-on Item Start -->
{% for metafield in product.metafields.details.addon %}
{% for product in collections.all.products %}
{% for variant in product.variants %}
{% if metafield == variant.sku %}
<div class="add-on-product-container">
<a href="{{ product.url }}"><img src="{{ product.featured_media | img_url: 'x50' }}" class="add-on-image"></a>
<span class="add-on-element"><strong>Optional: {{ product.title }}</strong><span>
<span class="add-on-element">+ {{ product.price | money }}<span>
<span class="add-on-element"><input class="add-on-product-checkbox" type="checkbox" name="id[]" value="{{ variant.id }}" /></span>
</div>
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% for metafield in product.metafields.details.addon2 %}
{% for product in collections.all.products %}
{% for variant in product.variants %}
{% if metafield == variant.sku %}
<div class="add-on-product-container">
<a href="{{ product.url }}"><img src="{{ product.featured_media | img_url: 'x50' }}" class="add-on-image"></a>
<span class="add-on-element"><strong>Optional: {{ product.title }}</strong><span>
<span class="add-on-element">+ {{ product.price | money }}<span>
<span class="add-on-element"><input class="add-on-product-checkbox" type="checkbox" name="id[]" value="{{ variant.id }}" /></span>
</div>
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
<! -- Add-on Item End -->
{% endform %}
I did two for loops to add either one or two add-ons, depending what is needed for the product.
3. Add the add-on SKU to the products metafields:
that's it.
Here's how it looks with one add-on:
Here is the 2 add-on example:
In the cart the product and add-on show as separate items:
Still need to line up the text and add photos of the add-ons, but other than that it works fine. The add-on quantity always matches the product quantity, so if you have a product that require multiples of one add-on, you need to make product sets.
Hope this helps,
Diego
thank you brother for your advice. but can you help give me a video? [i need add-ons with dropdown menu] without the app.
Hi
Did you find the soluction
Hi @ogeid
I am trying this option code you have given but When we display both or a Single item the add-on the Add to Cart button now working
Hey @gary07 ,
You need to make sure the code for your add-on items is in between <form method="post" action="/cart/add"> ... and ....</form>. This allows your regular product and your add-on to be summited to the cart at the same time.
Hope that helps.
What theme are you using?
Hello
WOuld you able to help me
Hello @gary07,
Do you still need help with this project? The key is to place the other products within the existing form tags. If you want me to take a look at your store send me a PM.
Regards, Diego
Old Thread I know but here goes - Using dawn theme, there seems to be no product-template.liquid.
Would i simply create it? Or is there some wizardry done here that's actually wrong?
User | RANK |
---|---|
37 | |
28 | |
13 | |
12 | |
9 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023