WC_Coupon_Data_Store_CPT::delete
Deletes a coupon from the database.
Method of the class: WC_Coupon_Data_Store_CPT{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Coupon_Data_Store_CPT = new WC_Coupon_Data_Store_CPT(); $WC_Coupon_Data_Store_CPT->delete( $coupon, $args );
- $coupon(WC_Coupon) (required) (passed by reference — &)
- Coupon object.
- $args(array)
- Array of args to pass to the delete method.
Default: array()
Changelog
| Since 3.0.0 | Introduced. |
WC_Coupon_Data_Store_CPT::delete() WC Coupon Data Store CPT::delete code WC 10.3.3
public function delete( &$coupon, $args = array() ) {
$args = wp_parse_args(
$args,
array(
'force_delete' => false,
)
);
$id = $coupon->get_id();
if ( ! $id ) {
return;
}
if ( $args['force_delete'] ) {
wp_delete_post( $id );
$hashed_code = md5( $coupon->get_code() );
wp_cache_delete( WC_Cache_Helper::get_cache_prefix( 'coupons' ) . 'coupon_id_from_code_' . $hashed_code, 'coupons' );
$coupon->set_id( 0 );
do_action( 'woocommerce_delete_coupon', $id );
} else {
wp_trash_post( $id );
$coupon->set_status( 'trash' );
do_action( 'woocommerce_trash_coupon', $id );
}
}