WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Schemas

CartCouponSchema::get_item_response() public WC 1.0

Generate a response from passed coupon code.

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

No Hooks.

Return

Array.

Usage

$CartCouponSchema = new CartCouponSchema();
$CartCouponSchema->get_item_response( $coupon_code );
$coupon_code(string) (required)
Coupon code from the cart.

Code of CartCouponSchema::get_item_response() WC 5.8.0

public function get_item_response( $coupon_code ) {
	$controller           = new CartController();
	$cart                 = $controller->get_cart_instance();
	$total_discounts      = $cart->get_coupon_discount_totals();
	$total_discount_taxes = $cart->get_coupon_discount_tax_totals();
	$coupon               = new \WC_Coupon( $coupon_code );
	return [
		'code'          => $coupon_code,
		'discount_type' => $coupon->get_discount_type(),
		'totals'        => (object) $this->prepare_currency_response(
			[
				'total_discount'     => $this->prepare_money_response( isset( $total_discounts[ $coupon_code ] ) ? $total_discounts[ $coupon_code ] : 0, wc_get_price_decimals() ),
				'total_discount_tax' => $this->prepare_money_response( isset( $total_discount_taxes[ $coupon_code ] ) ? $total_discount_taxes[ $coupon_code ] : 0, wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
			]
		),
	];
}