Skip to content

Instantly share code, notes, and snippets.

@vishalck
Created August 2, 2017 20:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalck/35566ee3bdd7dfd7739f9002125c6b06 to your computer and use it in GitHub Desktop.
Save vishalck/35566ee3bdd7dfd7739f9002125c6b06 to your computer and use it in GitHub Desktop.
Add Empty Cart button on WooCommerce Cart page
<?php
add_action( 'woocommerce_after_cart_contents', array( $this, 'woo_empty_cart' ) );
/**
* Create Empty Cart button on WooCommerce cart page
*/
public function woo_empty_cart() {
global $woocommerce;
$cart_url = $woocommerce->cart->get_cart_url();
?>
<tr>
<td colspan="6" class="actions">
<?php if (empty($_GET)) { ?>
<a class="button" href="<?php echo $cart_url; ?>?emptycart=yes"><?php _e('Empty Cart', 'woo-empty-cart-button'); ?></a>
<?php } else { ?>
<a class="button" href="<?php echo $cart_url; ?>&emptycart=yes"><?php _e('Empty Cart', 'woo-empty-cart-button'); ?></a>
<?php } ?>
</td>
</tr>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment