Advertisement
Udoro

empty cart button

Apr 8th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. add_action( 'woocommerce_cart_coupon', 'custom_woocommerce_empty_cart_button' );
  2. function custom_woocommerce_empty_cart_button() {
  3. echo '<a href="' . esc_url( add_query_arg( 'empty_cart', 'yes' ) ) . '" class="button" title="' . esc_attr( 'Empty Cart', 'woocommerce' ) . '">' . esc_html( 'Empty Cart', 'woocommerce' ) . '</a>';
  4. }
  5.  
  6. add_action( 'wp_loaded', 'custom_woocommerce_empty_cart_action', 20 );
  7. function custom_woocommerce_empty_cart_action() {
  8. if ( isset( $_GET['empty_cart'] ) && 'yes' === esc_html( $_GET['empty_cart'] ) ) {
  9. WC()->cart->empty_cart();
  10.  
  11. $referer = wp_get_referer() ? esc_url( remove_query_arg( 'empty_cart' ) ) : wc_get_cart_url();
  12. wp_safe_redirect( $referer );
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement