Skip to content
Advertisement

Custom remove cart item functionality in Woocommerce

I have the add item function set-up, which looks like this:

JavaScript

Is there a similar or another way to create the remove item function?

Advertisement

Answer

yes there is wc_get_cart_remove_url but you need to get the cart item key to do so you can use the following :

JavaScript

Of course the code above will work for simple product only and simply it will remove all items from the carts.

If you want to reduce the cart item one item at time you need to use different approach as follow:

First : Let add our Remove link & add_to_cart with some attribute like quantity and product id in order to process the data with our script.

JavaScript

Now Let we need add our script to WordPress Footer or you can added it to your Javascript file

JavaScript

Finally we need to process the data when the user clicked remove link

JavaScript

Place the codes above in your functions.php and you are good to go.

all codes above has bees tested and it’s working fine.

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