WC_AJAX::remove_coupon()public staticWC 1.0

AJAX remove coupon on cart and checkout page.

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

Хуков нет.

Возвращает

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

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

$result = WC_AJAX::remove_coupon();

Код WC_AJAX::remove_coupon() WC 8.7.0

public static function remove_coupon() {
	check_ajax_referer( 'remove-coupon', 'security' );

	$coupon = isset( $_POST['coupon'] ) ? wc_format_coupon_code( wp_unslash( $_POST['coupon'] ) ) : false; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

	if ( StringUtil::is_null_or_whitespace( $coupon ) ) {
		wc_add_notice( __( 'Sorry there was a problem removing this coupon.', 'woocommerce' ), 'error' );
	} else {
		WC()->cart->remove_coupon( $coupon );
		wc_add_notice( __( 'Coupon has been removed.', 'woocommerce' ) );
	}

	wc_print_notices();
	wp_die();
}