JS confirm popup before add to cart
6 years 5 months ago #317504
by lousyfool
Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )
JS confirm popup before add to cart was created by lousyfool
-- HikaShop version -- : 4.2.3
-- Joomla version -- : 3.9.16
-- PHP version -- : 7.3
Hi,
I need to have a Javascript "confirm()" popup after the click on the add to cart button, where the product gets added to the cart if "ok" is clicked; in case of "cancel", the popup should close and the product should not get added to the cart.
The popup is no problem. In product view overrides like show_tabular.php I've added
and in quantity.php I've added the function to the onclick attribute, so it reads
I've tried adding "return;" and else after the console.log but, if anything, it only leads to the checkout instead staying on the current page. Whatever I do, the product gets still added to the cart on "cancel".
What to do to prevent the product from being added to the cart on "cancel"? Admittedly I'm not good enough with JS to figure it out myself, sorry.
Thanks for a good hint!
-- Joomla version -- : 3.9.16
-- PHP version -- : 7.3
Hi,
I need to have a Javascript "confirm()" popup after the click on the add to cart button, where the product gets added to the cart if "ok" is clicked; in case of "cancel", the popup should close and the product should not get added to the cart.
The popup is no problem. In product view overrides like show_tabular.php I've added
Code:
<script>
function atc_confirm() {
if (confirm("Are you sure?") == false) {
console.log("cancelled");
}
}
</script>
Code:
onclick="atc_confirm(); if(window.hikashop.addToCart) { return window.hikashop.addToCart(this); }"
I've tried adding "return;" and else after the console.log but, if anything, it only leads to the checkout instead staying on the current page. Whatever I do, the product gets still added to the cart on "cancel".
What to do to prevent the product from being added to the cart on "cancel"? Admittedly I'm not good enough with JS to figure it out myself, sorry.
Thanks for a good hint!
Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )
Please Log in or Create an account to join the conversation.
6 years 5 months ago #317521
by nicolas
Replied by nicolas on topic JS confirm popup before add to cart
Hi,
You should change your JS code to:
And then:
You should change your JS code to:
Code:
<script>
function atc_confirm(el) {
if (confirm("Are you sure?") == false) {
return false;
}
return window.hikashop.addToCart(el);
}
</script>
Code:
onclick="return atc_confirm(this);"
The following user(s) said Thank You: lousyfool
Please Log in or Create an account to join the conversation.
6 years 5 months ago #317572
by lousyfool
Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )
Replied by lousyfool on topic JS confirm popup before add to cart
Excellent -- works great!
Thank you!
Thank you!
Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )
Please Log in or Create an account to join the conversation.
Time to create page: 0.179 seconds