Skip to content
Advertisement

Empty cart button on woocommerce cart page does not work properly

I’m using this code to creare a button on my woocommerce cart page (near the update cart button):

JavaScript

The problem is that it works only by clicking two times. I think that the problem could be that I’m using this link to add a product to the cart:

JavaScript

Any idea how to solve this?

Advertisement

Answer

The problem lies in the line:

JavaScript

The wp_get_referer() function returns the referer of the current page. Basically the link that took you to the current page.

For more information: https://developer.wordpress.org/reference/functions/wp_get_referer/

If you have previously added a product, after clicking on the Empty cart button you will be redirected to the link to add the product to the cart.

You can solve it like this:

JavaScript

The code has been tested and works. Add it to your active theme’s functions.php.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement