i have tried numerous ways to disable the add to cart button after the first click to prevent my customers adding more than 1 product to their cart and i have failed every time.
Could any php or javascript developers please provide some insight or knowledge on how we can achieve this as it would benefit the opencart community, thankyou.
This can be done easily with some jQuery. The real problem is that this will be highly confusing to your customers.
I think a more common approach would be to have a little error msg display to the visitor that they can only add one item at a time to the cart. Rather than have buttons disappear or stop functioning.
So you'd be looking to check that the cart is empty before adding anything more to the cart and if not empty display an alert.
Something like this should work:-
Look for this function:-
When the click event occurs check that cart total on the page (or make and ajax call or php script, whatever to check the cart value). Drop this is:-
Untested but should work.
I think a more common approach would be to have a little error msg display to the visitor that they can only add one item at a time to the cart. Rather than have buttons disappear or stop functioning.
So you'd be looking to check that the cart is empty before adding anything more to the cart and if not empty display an alert.
Something like this should work:-
Look for this function:-
Code: Select all
$('#button-cart').bind('click', function() {
});
Code: Select all
if ($('#cart_total:contains('0.00')")) {
// Place current add to cart ajax call in here;
} else {
$('#notification').html('<div class="warning" style="display: none;">Only one item can be added to cart at a time.<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.warning').fadeIn('slow');
}
www.opencartstore.com
Get OpenCart Templates and OpenCart Modules.
hello. do you know how i can stop opencart adding in cart more products than they are in stock? i have 1 pice of a product but any client can add 9999 of that and no error. they get the quantity error when they try to checkout. this is so wrong. they shoud have a message telling quantity requested is not in stock the moment they try to add it to cartimaginetech wrote:This can be done easily with some jQuery. The real problem is that this will be highly confusing to your customers.
I think a more common approach would be to have a little error msg display to the visitor that they can only add one item at a time to the cart. Rather than have buttons disappear or stop functioning.
So you'd be looking to check that the cart is empty before adding anything more to the cart and if not empty display an alert.
Something like this should work:-
Look for this function:-When the click event occurs check that cart total on the page (or make and ajax call or php script, whatever to check the cart value). Drop this is:-Code: Select all
$('#button-cart').bind('click', function() { });
Untested but should work.Code: Select all
if ($('#cart_total:contains('0.00')")) { // Place current add to cart ajax call in here; } else { $('#notification').html('<div class="warning" style="display: none;">Only one item can be added to cart at a time.<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); }
Who is online
Users browsing this forum: No registered users and 164 guests