WC_Coupon_Data_Store_CPT::delete()publicWC 3.0.0

Deletes a coupon from the database.

Метод класса: WC_Coupon_Data_Store_CPT{}

Возвращает

null. Ничего (null).

Использование

$WC_Coupon_Data_Store_CPT = new WC_Coupon_Data_Store_CPT();
$WC_Coupon_Data_Store_CPT->delete( $coupon, $args );
$coupon(WC_Coupon) (обязательный) (передается по ссылке — &)
Coupon object.
$args(массив)
Array of args to pass to the delete method.
По умолчанию: array()

Список изменений

С версии 3.0.0 Введена.

Код WC_Coupon_Data_Store_CPT::delete() WC 8.7.0

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 );

		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 {
		wp_trash_post( $id );
		do_action( 'woocommerce_trash_coupon', $id );
	}
}