WordPress at Your Fingertips
function is not described

WC_AJAX::apply_coupon() public WC 1.0

AJAX apply coupon on checkout page.

{} It's a method of the class: WC_AJAX{}

No Hooks.

Return

null. Nothing.

Usage

$result = WC_AJAX::apply_coupon();

Code of WC_AJAX::apply_coupon() WC 5.9.0

public static function apply_coupon() {

	check_ajax_referer( 'apply-coupon', 'security' );

	if ( ! empty( $_POST['coupon_code'] ) ) {
		WC()->cart->add_discount( wc_format_coupon_code( wp_unslash( $_POST['coupon_code'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
	} else {
		wc_add_notice( WC_Coupon::get_generic_coupon_error( WC_Coupon::E_WC_COUPON_PLEASE_ENTER ), 'error' );
	}

	wc_print_notices();
	wp_die();
}