New Zenner
- Join Date:
- Sep 2024
- Location:
- Noord Holland
- Posts:
- 24
- Plugin Contributions:
- 4
Clear cart with button click
Hello Zenners,
Is there a way (in Zen Cart 1.5.8a) i can clear the whole shoppingcart with one button click?
Dirk
Views: 2,891
New Zenner
Hello Zenners,
Is there a way (in Zen Cart 1.5.8a) i can clear the whole shoppingcart with one button click?
Dirk
Administrator
Nope, there's not. Either all quantities need to be zeroed or each of the items' delete checkboxes clicked and then the overall "Update" icon clicked.
New Zenner
Thanks Lat9 for you're quick response.
Helps me a lot.
Dirk
Zen Follower
I also had a need for this, so I added a javascript checkbox at the top of the shopping cart page that checks all the other boxes at once.
Two clicks to empty the cart:
<div class="nav-item">
<input class="ml-auto" type="checkbox" onchange="checkAll(this)" name="chk[]"> <i class="fas fa-trash-alt"></i>
</div>
<script>
function checkAll(ele) {
var checkboxes = document.getElementsByTagName('input');
if (ele.checked) {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = true;
}
}
} else {
for (var i = 0; i < checkboxes.length; i++) {
console.log(i)
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = false;
}
}
}
}
</script>
Totally Zenned
What about action=empty_cart ?
You can add a button or a link literally anywhere on the website:
index.php?main_page=shopping_cart&action=empty_cart
or, if you prefer the correct way with php:
<a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, 'action=empty_cart'); ?>" class="buttonRow emptyCart">Empty Cart</a>
Style it the way you like.
Fields marked required must be completed.
Tell staff why this post should be reviewed.
Required for login, security, and core site functionality.
Help us understand how the site is used so we can improve it.
Used for promotion and personalized campaign measurement.