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 🤗.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024