Only remove fees which belong to the cart which is being emptied/reset

If there are multiple instances of WC_Cart and therefore multiple
instances of WC_Cart_Fees, if 1 cart is emptied and
woocommerce_cart_emptied is triggered, all instances of WC_Cart_Fees
will trigger remove_all_fees, removing all the fees from all the carts.
This commit is contained in:
James Allan 2017-12-08 21:15:08 +10:00
parent 0c5a0b06cc
commit 83de162adb
2 changed files with 3 additions and 9 deletions

View File

@ -65,14 +65,6 @@ final class WC_Cart_Fees {
$this->cart = $cart;
}
/**
* Register methods for this object on the appropriate WordPress hooks.
*/
public function init() {
add_action( 'woocommerce_cart_emptied', array( $this, 'remove_all_fees' ) );
add_action( 'woocommerce_cart_reset', array( $this, 'remove_all_fees' ) );
}
/**
* Add a fee. Fee IDs must be unique.
*

View File

@ -111,7 +111,6 @@ class WC_Cart extends WC_Legacy_Cart {
// Register hooks for the objects.
$this->session->init();
$this->fees_api->init();
add_action( 'woocommerce_add_to_cart', array( $this, 'calculate_totals' ), 20, 0 );
add_action( 'woocommerce_applied_coupon', array( $this, 'calculate_totals' ), 20, 0 );
@ -640,6 +639,8 @@ class WC_Cart extends WC_Legacy_Cart {
$this->session->persistent_cart_destroy();
}
$this->fees_api->remove_all_fees();
do_action( 'woocommerce_cart_emptied' );
}
@ -1901,6 +1902,7 @@ class WC_Cart extends WC_Legacy_Cart {
*/
private function reset_totals() {
$this->totals = $this->default_totals;
$this->fees_api->remove_all_fees();
do_action( 'woocommerce_cart_reset', $this, false );
}
}