Skip to content

Instantly share code, notes, and snippets.

@huzaifaarain
Forked from BFTrick/functions.php
Created December 6, 2018 12:53
Show Gist options
  • Save huzaifaarain/36f31b2a5e1c25664192f51697a3f941 to your computer and use it in GitHub Desktop.
Save huzaifaarain/36f31b2a5e1c25664192f51697a3f941 to your computer and use it in GitHub Desktop.
WooCommerce add an Empty Cart button
<?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