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.
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.
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).
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.
{{ product.description }}
{% for tag in product.tags %}
{% if tag == 'add-on-anchor' %}
{% endif %}
{% endfor %}
This is how it looks on the product page. I still need to add some styling, but this is without any styling:
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:
add brackets to the id:
This will allow you to add multiple products with the Add to Cart button.
2. Add the following code before {% endfrom %}
```markup
{% for metafield in product.metafields.details.addon %}
{% for product in collections.all.products %}
{% for variant in product.variants %}
{% if metafield == variant.sku %}
**Optional: {{ product.title }}**
+ {{ product.price | money }}
{% 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 %}
**Optional: {{ product.title }}**
+ {{ product.price | money }}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endform %}
I did two for loops to add either one or two add-ons, depending what is needed for the product.
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.
You need to make sure the code for your add-on items is in between … and …. This allows your regular product and your add-on to be summited to the cart at the same time.
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.
This is such an awesome idea! With the most recent version of Dawn, there is a {form} element within the product.liquid file, but there is also a in the rendered buy-buttons.liquid file. I keep trying to figure out the right place to put everything, but I can’t quite get it. Any recommendations or tips?