Merge pull request #16767 from hjoelr/bugfix-coupon-cache
Bugfix: coupon object cache not being cleared upon deletion
This commit is contained in:
commit
f9120672bd
|
@ -185,6 +185,9 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
|
||||
if ( $args['force_delete'] ) {
|
||||
wp_delete_post( $id );
|
||||
|
||||
wp_cache_delete( WC_Cache_Helper::get_cache_prefix( 'coupons' ) . 'coupon_id_from_code_' . $coupon->get_code(), 'coupons' );
|
||||
|
||||
$coupon->set_id( 0 );
|
||||
do_action( 'woocommerce_delete_coupon', $id );
|
||||
} else {
|
||||
|
|
|
@ -44,6 +44,19 @@ class WC_Tests_Coupon_Data_Store extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 0, $coupon->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test coupon accurately cleans up object cache upon deletion.
|
||||
*/
|
||||
public function test_coupon_cache_deletion() {
|
||||
$coupon = WC_Helper_Coupon::create_coupon( 'test' );
|
||||
$coupon->delete( true );
|
||||
|
||||
$cache_name = WC_Cache_Helper::get_cache_prefix( 'coupons' ) . 'coupon_id_from_code_' . $coupon->get_code();
|
||||
$ids = wp_cache_get( $cache_name, 'coupons' );
|
||||
|
||||
$this->assertEquals( false, $ids, sprintf( 'Object cache for %s was not removed upon deletion of coupon.', $cache_name ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test coupon update.
|
||||
* @since 3.0.0
|
||||
|
|
Loading…
Reference in New Issue