WC_Cart_Session::init
Register methods for this object on the appropriate WordPress hooks.
Method of the class: WC_Cart_Session{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Cart_Session = new WC_Cart_Session(); $WC_Cart_Session->init();
WC_Cart_Session::init() WC Cart Session::init code WC 10.8.1
public function init() {
/**
* Filters whether hooks should be initialized for the current cart session.
*
* @param bool $must_initialize Will be passed as true, meaning that the cart hooks should be initialized.
* @param bool $session The WC_Cart_Session object that is being initialized.
* @returns bool True if the cart hooks should be actually initialized, false if not.
*
* @since 6.9.0
*/
if ( ! apply_filters( 'woocommerce_cart_session_initialize', true, $this ) ) {
return;
}
add_action( 'wp_loaded', array( $this, 'get_cart_from_session' ) );
add_action( 'woocommerce_cart_emptied', array( $this, 'destroy_cart_session' ) );
add_action( 'woocommerce_after_calculate_totals', array( $this, 'set_session' ), 1000 );
add_action( 'woocommerce_removed_coupon', array( $this, 'set_session' ) );
// Persistent cart stored to usermeta.
add_action( 'woocommerce_add_to_cart', array( $this, 'persistent_cart_update' ) );
add_action( 'woocommerce_cart_item_removed', array( $this, 'persistent_cart_update' ) );
add_action( 'woocommerce_cart_item_restored', array( $this, 'persistent_cart_update' ) );
add_action( 'woocommerce_cart_item_set_quantity', array( $this, 'persistent_cart_update' ) );
// Cookie events - cart cookies need to be set before headers are sent.
add_action( 'woocommerce_add_to_cart', array( $this, 'maybe_set_cart_cookies' ) );
add_action( 'wp', array( $this, 'maybe_set_cart_cookies' ), 99 );
add_action( 'shutdown', array( $this, 'maybe_set_cart_cookies' ), 0 );
add_action( 'template_redirect', array( $this, 'clean_up_removed_cart_contents' ) );
}