-- 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
<script>
function atc_confirm() {
if (confirm("Are you sure?") == false) {
console.log("cancelled");
}
}
</script>
and in quantity.php I've added the function to the onclick attribute, so it reads
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!