Skip to content

Commit

Permalink
Need to delete from cart using mt_delete_data to update virtual inven…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
joedolson committed Jan 25, 2024
1 parent b6e07e6 commit f417fff
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/includes/data-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ function mt_get_data( $type, $user_ID = false ) {
$data_age = get_user_meta( $current_user->ID, '_mt_user_init_expiration', true );
if ( $data_age && time() > $data_age ) {
// Expire user's cart after the data ages out.
delete_user_meta( $current_user->ID, "_mt_user_$type" );
if ( 'cart' === $type ) {
mt_delete_data( 'cart' );
} else {
delete_user_meta( $current_user->ID, "_mt_user_$type" );
}
$expired = true;
}
if ( ! $data_age && ! $expired ) {
Expand Down Expand Up @@ -194,7 +198,7 @@ function mt_get_cart( $user_ID = false, $cart_id = false ) {
$current_user = wp_get_current_user();
$data_age = get_user_meta( $current_user->ID, '_mt_user_init_expiration', true );
if ( $data_age && time() > $data_age ) {
delete_user_meta( $current_user->ID, '_mt_user_cart' );
mt_delete_data( 'cart' );
delete_user_meta( $current_user->ID, '_mt_user_init_expiration' );
} else {
$cart = get_user_meta( $current_user->ID, '_mt_user_cart', true );
Expand Down Expand Up @@ -325,21 +329,29 @@ function mt_is_cart_expired() {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
foreach ( $types as $type ) {
$data_age = get_user_meta( $current_user->ID, "_mt_user_init_$type", true );
$data_age = get_user_meta( $current_user->ID, "_mt_user_init_expiration", true );
if ( time() > $data_age ) {
// Expire user's cart after the data ages out.
delete_user_meta( $current_user->ID, "_mt_user_$type" );
delete_user_meta( $current_user->ID, "_mt_user_init_$type" );
if ( 'cart' === $type ) {
mt_delete_data( 'cart' );
} else {
delete_user_meta( $current_user->ID, "_mt_user_$type" );
}
}
}
delete_user_meta( $current_user->ID, "_mt_user_init_expiration" );
} else {
$unique_id = mt_get_unique_id();
if ( $unique_id ) {
$expiration = get_transient( 'mt_' . $unique_id . '_expiration' );
if ( time() > $expiration ) {
delete_transient( 'mt_' . $unique_id . '_expiration' );
foreach ( $types as $type ) {
delete_transient( 'mt_' . $unique_id . '_' . $type );
if ( 'cart' === $type ) {
mt_delete_data( 'cart' );
} else {
delete_transient( 'mt_' . $unique_id . '_' . $type );
}
}
}
}
Expand Down

0 comments on commit f417fff

Please sign in to comment.