Title: Adding button to empty card
Last modified: December 1, 2021

---

# Adding button to empty card

 *  Resolved [fafa24](https://wordpress.org/support/users/fafa24/)
 * (@fafa24)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/adding-button-to-empty-card/)
 * Hello,
 * I would like to add a button to my cart to empty the card. I mean when one clicks
   on the button it will remove all articles in one go from the card.
 * For that, I found this code snippet on the internet.
 * —
 *     ```
       add_action( 'woocommerce_cart_coupon', 'custom_woocommerce_empty_cart_button' );
       function custom_woocommerce_empty_cart_button() {
       	echo '<a href="' . esc_url( add_query_arg( 'empty_cart', 'yes' ) ) . '" class="button" title="' . esc_attr( 'Empty Cart', 'woocommerce' ) . '">' . esc_html( 'Empty Cart', 'woocommerce' ) . '</a>';
       }
       add_action( 'wp_loaded', 'custom_woocommerce_empty_cart_action', 20 );
       function custom_woocommerce_empty_cart_action() {
       	if ( isset( $_GET['empty_cart'] ) && 'yes' === esc_html( $_GET['empty_cart'] ) ) {
       		WC()->cart->empty_cart();
       		$referer  = wp_get_referer() ? esc_url( remove_query_arg( 'empty_cart' ) ) : wc_get_cart_url();
       		wp_safe_redirect( $referer );
       	}
       }
       ```
   
 * —
 * However, when I click on the button, the cart crashes with a 500 internal server
   error. I already contacted my host and they say that I need to fix this error
 * _
    24#APVH\_staging.belgian-beershop.ch:443] detect loop redirection: /cart/
 * Could you please help me to amend the snipped or maybe there is a better way.
 * Thanks
    Edy
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-button-to-empty-card%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Juan G. (woo-hc)](https://wordpress.org/support/users/judagutor/)
 * (@judagutor)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/adding-button-to-empty-card/#post-15123406)
 * Hi Edy!
 * Since this requires custom coding, I will leave the thread open for a bit to 
   see if anyone can chime in to help you out.
 * For additional assistance on this topic, we recommend getting in touch with one
   of the customization experts listed on the [WooCommerce Customizations Page](https://woocommerce.com/customizations/).
 * You can also visit the [WooCommerce Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
   or the `#developers` channel of the WooCommerce Community Slack. We are lucky
   to have a great community of open-source developers for WooCommerce, and many
   of our developers hang out there, as well.
 * Anyway, I found a couple of plugins that could be helpful to your case:
 * [https://wordpress.org/plugins/woo-empty-cart-button/](https://wordpress.org/plugins/woo-empty-cart-button/)(
   [Click here for pre-sales questions](https://wordpress.org/support/plugin/woo-empty-cart-button/))
   
   [https://woocommerce.com/products/clear-cart-and-sessions-for-woocommerce/](https://woocommerce.com/products/clear-cart-and-sessions-for-woocommerce/)(
   [Click here for pre-sales questions](https://woocommerce.com/products/clear-cart-and-sessions-for-woocommerce/))
 * Both plugins add an **Empty cart** button to your cart.
 * I hope this helps!
 *  [Juan G. (woo-hc)](https://wordpress.org/support/users/judagutor/)
 * (@judagutor)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/adding-button-to-empty-card/#post-15152843)
 * Hi Edy!
 * We haven’t heard from you in a while, so I’m going to mark this as resolved. 
   Feel free to start a new thread if you have any more questions.
 * Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding button to empty card’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [button](https://wordpress.org/support/topic-tag/button/)
 * [cart](https://wordpress.org/support/topic-tag/cart/)

 * 2 replies
 * 2 participants
 * Last reply from: [Juan G. (woo-hc)](https://wordpress.org/support/users/judagutor/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/adding-button-to-empty-card/#post-15152843)
 * Status: resolved