WC_Cart::remove_coupon()publicWC 1.0

Remove a single coupon by code.

Method of the class: WC_Cart{}

Hooks from the method

Return

true|false.

Usage

$WC_Cart = new WC_Cart();
$WC_Cart->remove_coupon( $coupon_code );
$coupon_code(string) (required)
Code of the coupon to remove.

WC_Cart::remove_coupon() code WC 9.4.2

public function remove_coupon( $coupon_code ) {
	$coupon_code = wc_format_coupon_code( $coupon_code );
	$position    = array_search( $coupon_code, array_map( 'wc_format_coupon_code', $this->get_applied_coupons() ), true );

	if ( false !== $position ) {
		unset( $this->applied_coupons[ $position ] );
	}

	WC()->session->set( 'refresh_totals', true );

	do_action( 'woocommerce_removed_coupon', $coupon_code );

	return true;
}