Created
August 2, 2017 20:29
-
-
Save vishalck/b4edb52b402fcc61748e5cca60f85344 to your computer and use it in GitHub Desktop.
Empty WooCommerce cart
This file contains 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 | |
/** | |
* Empties the cart and optionally the persistent cart too. | |
* | |
* @param bool $clear_persistent_cart (default: true) | |
*/ | |
public function empty_cart( $clear_persistent_cart = true ) { | |
$this->cart_contents = array(); | |
$this->reset( true ); | |
unset( WC()->session->order_awaiting_payment, WC()->session->applied_coupons, WC()->session->coupon_discount_amounts, WC()->session->coupon_discount_tax_amounts, WC()->session->cart ); | |
if ( $clear_persistent_cart && get_current_user_id() ) { | |
$this->persistent_cart_destroy(); | |
} | |
do_action( 'woocommerce_cart_emptied' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment