-
-
Save huzaifaarain/36f31b2a5e1c25664192f51697a3f941 to your computer and use it in GitHub Desktop.
WooCommerce add an Empty Cart button
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 | |
// check for empty-cart get param to clear the cart | |
add_action( 'init', 'woocommerce_clear_cart_url' ); | |
function woocommerce_clear_cart_url() { | |
global $woocommerce; | |
if ( isset( $_GET['empty-cart'] ) ) { | |
$woocommerce->cart->empty_cart(); | |
} | |
} | |
add_action( 'woocommerce_cart_actions', 'patricks_add_clear_cart_button', 20 ); | |
function patricks_add_clear_cart_button() { | |
echo "<a class='button' href='?empty-cart=true'>" . __( 'Empty Cart', 'woocommerce' ) . "</a>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment