Last active
October 30, 2023 07:56
-
-
Save SirDarcanos/46ab54c2f270397be244cd385bd969a3 to your computer and use it in GitHub Desktop.
Add an Empty Cart Button in WooCommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_loaded', 'woocommerce_empty_cart_action', 20 ); | |
function 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 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment