Return management just got easier! We’ve launched Customer Self-Serve Returns to all Shopify merchants. Click here to learn more!

Detect if snippet has already run on page

Solved
nagumi
Explorer
63 2 23

This is a bit hard to explain.

 

I have a snippet that creates a checkbox form element with the property "required" (unless this checkbox is checked, form cannot be submitted). This snippet is called right above the checkout button on the cart.

 

The issue is with the cart notification popup - if I'm on the "/cart" page the snippet runs twice - once for the (hidden) cart notification popup and once for the cart page itself. In this case, if the user clicks "checkout", the checkboxes are BOTH validated. Of course, the hidden one is "unchecked", and so the form submission is halted.

 

I need a way to detect if the snippet has already run (if the form element has already been created) on the current page.

 

So:

If [snippet has NOT already run] AND [current page is /cart] THEN [don't include REQUIRED tag on the checkbox]

 

and

 

If [snippet has already run] AND [current page is /cart] THEN [include REQUIRED tag on the checkbox]

 

 

Did that make any sense? I'm having trouble explaining it.

Accepted Solution (1)

Accepted Solutions
hari1_prasad
Shopify Partner
211 37 37

This is an accepted solution.

@nagumi hi,

 

You have to check the visibility of parent in which you adding the checkbox code.

 

Hope you got the logic...

If your problem solved then Like & Accept this Solution.
For Design, Development and custom changes Hire Me or drop me a message or connect at Email ID: gr.trading15@gmail.com for quick consultation.
To support Buy Me a Coffee

View solution in original post

Reply 1 (1)
hari1_prasad
Shopify Partner
211 37 37

This is an accepted solution.

@nagumi hi,

 

You have to check the visibility of parent in which you adding the checkbox code.

 

Hope you got the logic...

If your problem solved then Like & Accept this Solution.
For Design, Development and custom changes Hire Me or drop me a message or connect at Email ID: gr.trading15@gmail.com for quick consultation.
To support Buy Me a Coffee