WC_Cart::empty_cart
Empties the cart and optionally the persistent cart too.
Метод класса: WC_Cart{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$WC_Cart = new WC_Cart(); $WC_Cart->empty_cart( $clear_persistent_cart );
- $clear_persistent_cart(true|false)
- Should the persistent cart be cleared too.
По умолчанию: true
Список изменений
| С версии 9.7.0 | Введена. |
| С версии 9.7.0 | Also clears shipping methods and packages since the items they are linked to are cleared. |
Код WC_Cart::empty_cart() WC Cart::empty cart WC 10.4.2
public function empty_cart( $clear_persistent_cart = true ) {
/**
* Fires before the cart is emptied.
*
* @since 9.7.0
*
* @param bool $clear_persistent_cart Whether the persistent cart will be cleared too.
*/
do_action( 'woocommerce_before_cart_emptied', $clear_persistent_cart );
$this->cart_contents = array();
$this->removed_cart_contents = array();
$this->shipping_methods = array();
$this->coupon_discount_totals = array();
$this->coupon_discount_tax_totals = array();
$this->applied_coupons = array();
$this->totals = $this->default_totals;
if ( $clear_persistent_cart ) {
$this->session->persistent_cart_destroy();
}
$this->fees_api->remove_all_fees();
WC()->shipping()->reset_shipping();
/**
* Fires after the cart is emptied.
*
* @since 9.7.0
*
* @param bool $clear_persistent_cart Whether the persistent cart was cleared too.
*/
do_action( 'woocommerce_cart_emptied', $clear_persistent_cart );
}