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
EdyThe page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Adding button to empty card’ is closed to new replies.