3

Is there a way to programmatically empty the cart? I know you can by submitting a form with name="empty_cart", but I'd like to do it programmatically between page loads, not requiring a user input.

If it's not possible with native tags, is this something we could build an extension for?

3

It depends what you're trying to achieve. If you want to programmatically empty the cart using PHP, this will do the trick (Store v2):

// load the Store module if you haven't already
require(PATH_THIRD.'store/autoload.php');

ee()->store->orders->clear_cart_cookie();

In Store v1:

$this->EE->store_cart->empty();

If you want to do it using template tags, I would suggest just making a basic template with the checkout form on it, and using javascript to submit the form as soon as the page loads.

By the time you're doing that though, you may as well just use a small checkout form with an empty_cart button instead of linking to the page in question.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.