Automattic\WooCommerce\StoreApi\Routes\V1

CartCouponsByCode::get_route_delete_responseprotectedWC 1.0

Delete a single cart coupon.

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

Хуков нет.

Возвращает

\WP_REST_Response.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_route_delete_response( $request );
$request(WP_REST_Request) (обязательный)
Request object.

Код CartCouponsByCode::get_route_delete_response() WC 10.0.2

protected function get_route_delete_response( \WP_REST_Request $request ) {
	if ( ! $this->cart_controller->has_coupon( $request['code'] ) ) {
		throw new RouteException( 'woocommerce_rest_cart_coupon_invalid_code', esc_html__( 'Coupon does not exist in the cart.', 'woocommerce' ), 404 );
	}

	$cart = $this->cart_controller->get_cart_instance();
	$cart->remove_coupon( $request['code'] );

	return new \WP_REST_Response( null, 204 );
}