dawn theme - product page help

Hi there,

I am really hoping someone can help me, I have a form and variant pill on my products page due to the nature of my product.

It was coded so that the customer cannot add their product to their cart without choosing one of the variant pill options and ticking the tickbox. If they ticked the tickbox and tried clicking ‘add to cart’ it would show a little message saying ‘please make selection’ or something like that. I cannot remember as this has suddenly stopped working on my live site.

Just to be clear the ‘make a selection’ box turns to ‘add to cart’ once the tickbox has been selected however right now the customer can add their product to their cart without selecting the variant pill.

Thanks so much in advance.

Ankita

Hire anyone with a good background to fix this.

The reason for experiencing this issue might be as a result of the validation logic preventing addition of the product to cart without selecting a variant pill, being likely not well executed.

To fix this, search for main-product.js inside the assets or sections folder handling the JavaScript file product options.

Then look for the code that handles the “Add To Cart” condition for the checkbox tick.

Modify it to also select a variant that will enable the button look similar to this;

document.addEventListener(“DOMContentLoaded”, function () {

const variantPills = document.querySelectorAll(“.variant-pill”); // Adjust if necessary

const checkbox = document.querySelector(“#confirm-checkbox”); // Adjust to match your actual checkbox ID

const addToCartButton = document.querySelector(“#add-to-cart”); // Adjust to match the button ID

function updateButtonState() {

let variantSelected = false;

// Check if at least one variant is selected

variantPills.forEach((pill) => {

if (pill.classList.contains(“selected”)) { // Modify if using checkboxes or radio buttons

variantSelected = true;

}

});

// Enable only if a variant is selected AND the checkbox is checked

if (variantSelected && checkbox.checked) {

addToCartButton.removeAttribute(“disabled”);

} else {

addToCartButton.setAttribute(“disabled”, “true”);

}

}

// Listen for variant selection changes

variantPills.forEach((pill) => {

pill.addEventListener(“click”, function () {

variantPills.forEach((p) => p.classList.remove(“selected”)); // Ensure only one selection

this.classList.add(“selected”);

updateButtonState();

});

});

// Listen for checkbox changes

checkbox.addEventListener(“change”, updateButtonState);

// Initial check on page load

updateButtonState();

});

After saving the changes in the Shopify code editor, refresh the live website as well.

See if you can add a product to the cart without selecting a variant, it should be blocked.

However, try selecting a product, variant and ticking the checkbox, this should work properly, allowing the product to add to cart.

Not a very helpful reply! Enjoy your day :slightly_smiling_face:

Hi @Ankita31

It sounds like the validation for your variant selection and tickbox has stopped working. If you’re looking for an easy fix without coding, you might want to try Easify Product Options. It ensures customers select required options before adding to cart. Here’s how it works:

  • This is the result:

  • This is the app setting: You just need to set the checkbox as a required field so that your customers can only add the item to their cart when they select it

I hope this answer helps solve the problem. If you need further assistance, feel free to reach out to Easify anytime! :hugs:

Hi,

Thank so much for this - I presume this is an app.

Can you advise if this app is free to use and a little bit about the app. Feel free to DM me :slightly_smiling_face: Thanks so much!

Hi @Ankita31

Thank you for your interest! This app is perfect for products that have customizable options. We offer a Free plan, along with Pro and Premium plans at very affordable rates. The required tick box feature I show you is available in the Free plan.

If you need any help setting it up, just download the app—we have 24/7 live chat support to assist you. :blush: