Website Building » WooCommerce » How Do I Add a Clear CART Button in WooCommerce?

How Do I Add a Clear CART Button in WooCommerce?

Last updated on January 18, 2023 @ 12:11 pm

There are two ways to add a clear CART button in WooCommerce. One way is to use a plugin, and the other way is to edit your theme’s functions.php file.

If you want to use a plugin, we recommend the WooCommerce Persistent Cart plugin. This plugin will add a “Clear Cart” button to your WooCommerce store, and it will also keep your cart contents saved even if you close your browser or leave your site.

If you want to edit your theme’s functions.php file, you can add the following code:

PRO TIP: Adding a clear cart button in WooCommerce may result in unexpected behavior and can cause issues with your site. Use caution when adding this button and test thoroughly before making it live on your site.
add_filter( 'woocommerce_get_item_data', 'clear_cart_button', 10, 2 );
function clear_cart_button( $item_data, $cart_item ) {
$item_data[] = array(
'key'     => __( 'Clear cart', 'woocommerce' ),
'value'   => '<a href="?clear-cart" class="button">' . __( 'Clear cart', 'woocommerce' ) . 

'</a>',
'disabled' => false, );
return $item_data;
}

This code will add a “Clear Cart” button to each item in your cart. When clicked, this button will empty your cart.

Conclusion:

Adding a clear CART button in WooCommerce is easy, and can be done either by using a plugin or by editing your theme’s functions. Using a plugin is the easiest way, but if you’re comfortable editing code, then editing your theme’s functions.php file is a good option.

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.