Merge branch 'pr/18072'

This commit is contained in:
Mike Jolley 2017-12-08 16:32:58 +00:00
commit 1f109ba62e
3 changed files with 6 additions and 11 deletions

View File

@ -68,10 +68,7 @@ final class WC_Cart_Fees {
/**
* 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' ) );
}
public function init() {}
/**
* 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 );
@ -128,8 +127,8 @@ class WC_Cart extends WC_Legacy_Cart {
* These properties store a reference to the cart, so we use new instead of clone.
*/
public function __clone() {
$this->session = new WC_Cart_Session( $this );
$this->fees_api = new WC_Cart_Fees( $this );
$this->session = clone $this->session;
$this->fees_api = clone $this->fees_api;
}
/*
@ -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 );
}
}

View File

@ -15,7 +15,6 @@ class WC_Tests_WC_Cart_Fees extends WC_Unit_Test_Case {
public function test_set_get_remove_fees() {
$cart_fees = new WC_Cart_Fees( wc()->cart );
$cart_fees->init();
// Test add_fee.
$args = array(
@ -53,8 +52,5 @@ class WC_Tests_WC_Cart_Fees extends WC_Unit_Test_Case {
// Clean up.
WC()->cart->empty_cart();
// Test fees are removed when cart is emptied.
$this->assertEquals( array(), $cart_fees->get_fees() );
}
}