Merge pull request #19027 from woocommerce/update/persistent-cart-filter
Added woocommerce_persistent_cart_enabled filter
This commit is contained in:
commit
c80372ad5c
|
@ -71,12 +71,18 @@ final class WC_Cart_Session {
|
|||
$this->cart->set_coupon_discount_tax_totals( WC()->session->get( 'coupon_discount_tax_totals', array() ) );
|
||||
$this->cart->set_removed_cart_contents( WC()->session->get( 'removed_cart_contents', array() ) );
|
||||
|
||||
if ( is_null( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) { // @codingStandardsIgnoreLine
|
||||
if ( apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
|
||||
$saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true );
|
||||
} else {
|
||||
$saved_cart = false;
|
||||
}
|
||||
|
||||
if ( is_null( $cart ) && $saved_cart ) {
|
||||
$cart = $saved_cart['cart'];
|
||||
$update_cart_session = true;
|
||||
} elseif ( is_null( $cart ) ) {
|
||||
$cart = array();
|
||||
} elseif ( is_array( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) { // @codingStandardsIgnoreLine
|
||||
} elseif ( is_array( $cart ) && $saved_cart ) {
|
||||
$cart = array_merge( $saved_cart['cart'], $cart );
|
||||
$update_cart_session = true;
|
||||
}
|
||||
|
@ -184,7 +190,7 @@ final class WC_Cart_Session {
|
|||
* Save the persistent cart when the cart is updated.
|
||||
*/
|
||||
public function persistent_cart_update() {
|
||||
if ( get_current_user_id() ) {
|
||||
if ( get_current_user_id() && apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
|
||||
update_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), array(
|
||||
'cart' => $this->get_cart_for_session(),
|
||||
) );
|
||||
|
@ -195,7 +201,7 @@ final class WC_Cart_Session {
|
|||
* Delete the persistent cart permanently.
|
||||
*/
|
||||
public function persistent_cart_destroy() {
|
||||
if ( get_current_user_id() ) {
|
||||
if ( get_current_user_id() && apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
|
||||
delete_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,13 @@ function wc_empty_cart() {
|
|||
* @deprecated 2.3
|
||||
*/
|
||||
function wc_load_persistent_cart( $user_login, $user ) {
|
||||
if ( ! $user || ! ( $saved_cart = get_user_meta( $user->ID, '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) {
|
||||
if ( ! $user || ! apply_filters( 'woocommerce_persistent_cart_enabled', true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$saved_cart = get_user_meta( $user->ID, '_woocommerce_persistent_cart_' . get_current_blog_id(), true );
|
||||
|
||||
if ( ! $saved_cart ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue