Add the woocommerce_cart_session_initialize-hook (#34156)

* Add the woocommerce_cart_session_initialize-hook

* Add changelog file
This commit is contained in:
Néstor Soriano 2022-08-08 21:54:44 +02:00 committed by GitHub
parent bb02983893
commit cc779db83c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add the woocommerce_cart_session_initialize-hook

View File

@ -45,6 +45,19 @@ final class WC_Cart_Session {
* Register methods for this object on the appropriate WordPress hooks.
*/
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 );