All things Shopify and commerce
Hello,
I added a line item property ( to collect text for product customization) to my product page template. I would like this to be mandatory before adding to cart as well as for this to show up in the cart .
I'm using the Palo Alto theme.
This is the link to my store. Please help!
AyeshaSantos,
If you share the exact URL of the product customization page, I will be able to help you.
Thanks so much!
Here it is :
Hey there!
If you're looking to disable the "Add to Cart" button on your website when a specific form field is empty, you're in the right place. I'll walk you through how to achieve this using JavaScript.
Firstly, let's understand the code:
document.addEventListener("DOMContentLoaded", function() {
var formField = document.querySelector("#Form-template--16763930968223__main-line_item_property_JYe4Wy");
var addToCartButton = document.querySelector("#AddToCart--template--16763930968223__main");
formField.addEventListener("input", function() {
if (formField.value.trim() === "") {
addToCartButton.disabled = true;
} else {
addToCartButton.disabled = false;
}
});
});
To implement this code, simply add it between <script> tags in the HTML section of the product template where you want this functionality to be applied. Just make sure the HTML section already contains elements with the specified IDs.
Feel free to reach out if you have any questions or need further clarification!
Hey Keshan,
Thanks so much for this! I'm looking in the product.liquid section but cant seem to find that section ID
Hey Ayesha,
Try to find the ID of the text field and "Add to Cart" button and replace it accordingly.
Hi @ayeshasantos,
A simpler solution for you would be to utilize the Easify Product Options app (free version) to create a required Text field (using either Text Box or Text Area) and add it into your products 🤗.
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024