Add separate methods to register hooks
This facilitates cloning the cart without registering additonal hooks unnecessarily.
This commit is contained in:
parent
63877adfb6
commit
0cca83ff83
|
@ -63,6 +63,12 @@ final class WC_Cart_Fees {
|
|||
}
|
||||
|
||||
$this->cart = $cart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register methods for this object on the appropriate WordPress hooks.
|
||||
*/
|
||||
public function register_hooks() {
|
||||
add_action( 'woocommerce_cart_emptied', array( $this, 'remove_all_fees' ) );
|
||||
add_action( 'woocommerce_cart_reset', array( $this, 'remove_all_fees' ) );
|
||||
}
|
||||
|
|
|
@ -38,7 +38,12 @@ final class WC_Cart_Session {
|
|||
}
|
||||
|
||||
$this->cart = $cart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register methods for this object on the appropriate WordPress hooks.
|
||||
*/
|
||||
public function register_hooks() {
|
||||
add_action( 'wp_loaded', array( $this, 'get_cart_from_session' ) );
|
||||
add_action( 'woocommerce_cart_emptied', array( $this, 'destroy_cart_session' ) );
|
||||
add_action( 'wp', array( $this, 'maybe_set_cart_cookies' ), 99 );
|
||||
|
|
|
@ -109,6 +109,10 @@ class WC_Cart extends WC_Legacy_Cart {
|
|||
$this->fees_api = new WC_Cart_Fees( $this );
|
||||
$this->tax_display_cart = get_option( 'woocommerce_tax_display_cart' );
|
||||
|
||||
// Register hooks for the objects.
|
||||
$this->session->register_hooks();
|
||||
$this->fees_api->register_hooks();
|
||||
|
||||
add_action( 'woocommerce_add_to_cart', array( $this, 'calculate_totals' ), 20, 0 );
|
||||
add_action( 'woocommerce_applied_coupon', array( $this, 'calculate_totals' ), 20, 0 );
|
||||
add_action( 'woocommerce_cart_item_removed', array( $this, 'calculate_totals' ), 20, 0 );
|
||||
|
|
Loading…
Reference in New Issue