Merged in feature/81-dev-dev01 (pull request #5)

auto-patch  81-dev-dev01-2023-12-05T22_45_26

* auto-patch  81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
Tony Volpe
2023-12-05 23:05:59 +00:00
parent ba16964e7a
commit 725d3043d5
1463 changed files with 142461 additions and 89421 deletions

View File

@@ -347,6 +347,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
} else {
add_post_meta( $coupon->get_id(), '_used_by', strtolower( $used_by ) );
}
$this->refresh_coupon_data( $coupon );
}
/**
@@ -375,6 +377,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
if ( $meta_id ) {
delete_metadata_by_mid( 'post', $meta_id );
$coupon->set_used_by( (array) get_post_meta( $coupon->get_id(), '_used_by' ) );
$this->refresh_coupon_data( $coupon );
}
}
@@ -405,6 +408,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
)
);
$this->refresh_coupon_data( $coupon );
// Get the latest value direct from the DB, instead of possibly the WP meta cache.
return (int) $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'usage_count' AND post_id = %d;", $id ) );
}
@@ -556,7 +561,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
$result = $wpdb->query( $insert_statement ); // WPCS: unprepared SQL ok.
if ( false !== $result ) {
// Clear meta cache.
wp_cache_delete( WC_Coupon::generate_meta_cache_key( $coupon->get_id(), 'coupons' ), 'coupons' );
$this->refresh_coupon_data( $coupon );
break;
}
}
@@ -651,7 +656,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
$result = $wpdb->query( $insert_statement ); // WPCS: unprepared SQL ok.
if ( false !== $result ) {
// Clear meta cache.
wp_cache_delete( WC_Coupon::generate_meta_cache_key( $coupon->get_id(), 'coupons' ), 'coupons' );
$this->refresh_coupon_data( $coupon );
break;
}
}
@@ -693,6 +698,18 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
); // WPCS: unprepared SQL ok.
}
/**
* This function clears coupon data from the WP cache after certain operations which, for performance reasons,
* are done via SQL queries.
*
* @param \WC_Coupon $coupon The coupon object.
* @return void
*/
private function refresh_coupon_data( &$coupon ) {
wp_cache_delete( $coupon->get_meta_cache_key(), 'coupons' );
wp_cache_delete( $coupon->get_id(), 'post_meta' );
}
/**
* Return a coupon code for a specific ID.
*