"Empty Cart" Button on the EDD Checkout
Adds an "Empty cart" button below the Easy Digital Downloads checkout cart so buyers can start again in one click.
Opens WPIDE on
Code
add_action( 'edd_cart_footer_buttons', function () {
printf(
'<a class="edd-submit button wpide-edd-empty-cart" href="%1$s" onclick="return confirm(%2$s)">%3$s</a>',
esc_url( wp_nonce_url( add_query_arg( 'edd_action', 'wpide_empty_cart', edd_get_checkout_uri() ), 'wpide_edd_empty_cart' ) ),
esc_attr( wp_json_encode( 'Remove all items from your cart?' ) ),
esc_html( 'Empty cart' )
);
} );
add_action( 'edd_wpide_empty_cart', function () {
if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'wpide_edd_empty_cart' ) ) {
edd_empty_cart();
}
wp_safe_redirect( edd_get_checkout_uri() );
exit;
} );
Notes
Asks for confirmation first and uses a security token, so the link cannot be triggered from other sites.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.