Jump to content

Conditional Logic for add to cart forms

Recommended Posts

Hi,

I am trying to use conditional logic so that when selecting the variant customisation = Yes a pop up form is displayed and when a user selects No they can add to cart.

 

Can anyone help with this?

Link to comment
  • Replies 3
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Hi,

I tested this code on a Product page of Squarespace 7.1 
You can add it in a code block inside the product page that you want it.

<script>
document.addEventListener("DOMContentLoaded", () => {
  document.querySelector(".sqs-add-to-cart-button-inner").addEventListener("click", function(event){
    var resultOfPopup = confirm("My message here");
    if(resultOfPopup) {
        event.preventDefault();
        event.stopImmediatePropagation();
    }
  });
});
</script>

"My message here" can be changed with your message but between the quotes.

Screenshot 2024-05-22 at 19.47.28.png

 👨‍🔧👨‍💻 Squarespace plugins

🙋‍♂️ Squarespace Custom Web Development & Design

📅 Notion alternative

📹 Squarespace Tutorials for free - YouTube📹 

💯🚀 I have worked on over 200 Squarespace sites with custom code for over 9 years

🙋‍♂️ Let's connect on LinkedIn

 

Link to comment
  • 3 weeks later...
On 6/7/2024 at 3:43 AM, JG0910 said:

https://www.customshinz.com/shop/p/personilised-shin-pads

Hey I want something where we do not have to click add to cart to start the form, something where you can just type it in like so: https://www.thecasepeople.com/product-page/customised-tcp-mini-shin-pads-1

You can consider using Custom Product Form.

https://support.squarespace.com/hc/en-us/articles/205811218-Creating-a-custom-product-form

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.