Automattic\WooCommerce\StoreApi\Schemas\V1

CartCouponSchema::get_item_responsepublicWC 1.0

Generate a response from passed coupon code.

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

Хуков нет.

Возвращает

Массив.

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

$CartCouponSchema = new CartCouponSchema();
$CartCouponSchema->get_item_response( $coupon_code );
$coupon_code(строка) (обязательный)
Coupon code from the cart.

Код CartCouponSchema::get_item_response() WC 10.7.0

public function get_item_response( $coupon_code ) {
	$controller = new CartController();
	$cart       = $controller->get_cart_instance();
	$coupon     = new \WC_Coupon( $coupon_code );
	return [
		'code'          => $coupon->get_code(),
		'discount_type' => $coupon->get_discount_type(),
		'totals'        => (object) $this->prepare_currency_response(
			[
				'total_discount'     => $this->prepare_money_response( $cart->get_coupon_discount_amount( $coupon_code ), wc_get_price_decimals() ),
				'total_discount_tax' => $this->prepare_money_response( $cart->get_coupon_discount_tax_amount( $coupon_code ), wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
			]
		),
	];
}