Prevent the possibility of unpublished coupons from being available (#47739)
* Clean up the cache when a coupon is updated When the coupon’s status transitions from publish to future, the ‘coupon_id_from_code’ cache entry needs to be deleted otherwise the coupon will remain available for use. * Remove coupon cache entries when not published * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: Toby Herbert <tobyherbert@nialtoservices.co.uk> Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
f56d3e3ee0
commit
0f21660277
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Possible availability of unpublished coupons on sites with an object cache has been addressed through improved cache management.
|
|
@ -190,6 +190,12 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
$this->update_post_meta( $coupon );
|
||||
$coupon->apply_changes();
|
||||
delete_transient( 'rest_api_coupons_type_count' );
|
||||
|
||||
// The `coupon_id_from_code` entry in the object cache must not exist when the coupon is not published, otherwise the coupon will remain available for use.
|
||||
if ( 'publish' !== $coupon->get_status() ) {
|
||||
wp_cache_delete( WC_Cache_Helper::get_cache_prefix( 'coupons' ) . 'coupon_id_from_code_' . $coupon->get_code(), 'coupons' );
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_update_coupon', $coupon->get_id(), $coupon );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue