Button on store doesn't work properly.

Solved
Tourist
24 0 0

Hi so i have a button on my store that says "get it now" where u get 25% off, but when people click it, it just refreshes the page. Is there a way to like add like a notification like "Your discount code has been added" or something like that?

0 Likes
Globetrotter
626 59 126

Can you post a link to the page with the button so we can take a look? Im guessing that it refreshes the page and adds the discount code to the end of the url, you can have an alert come up that notifies the person that it has been added, but I'll need to see the page.

If you'd like to make any edits to your store, please send me a direct message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
24 0 0

Yes. Here is the link: GoPawsStore.com

0 Likes
Globetrotter
626 59 126

add this to your index.liquid at the bottom:

 

<script>
$('.hero__cta').on('click', function(){alert('You added 25% off, price will reflect on checkout')})
</script>

You can change the wording to whatever you want. 

If you'd like to make any edits to your store, please send me a direct message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
24 0 0

Hi i did add it, but it doesn't work.

 

ee6f9ba775a221c19280c027e6cea91e.png

0 Likes
Highlighted

Success.

Globetrotter
626 59 126

Looks like jQuery isnt working, try vanilla JS. Replace that old code with this.

 

<script>
let btn = document.getElementsByClassName('hero__cta');

btn[0].addEventListener('click',function(){
alert('You added 25% off, price will reflect on checkout');
})
btn[1].addEventListener('click',function(){
alert('You added 25% off, price will reflect on checkout');
}) </script>

btn 0 is your desktop version and btn 1 is your mobile. I guarantee this isnt the best way to write the code, but Im not too familiar with regular Javascript

If you'd like to make any edits to your store, please send me a direct message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
24 0 0

Thank you. It looks good, thank you for your help. :) it worked.

0 Likes
Globetrotter
626 59 126

No problem, glad it helped.

If you'd like to make any edits to your store, please send me a direct message and we can discuss what you'd like to accomplish :D
1 Like