Automattic\WooCommerce\StoreApi\Schemas\V1

OrderCouponSchema::get_item_response()publicWC 1.0

Convert an order coupon to an object suitable for the response.

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

Хуков нет.

Возвращает

Массив.

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

$OrderCouponSchema = new OrderCouponSchema();
$OrderCouponSchema->get_item_response( $coupon );
$coupon(\WC_Order_Item_Coupon) (обязательный)
Order coupon object.

Код OrderCouponSchema::get_item_response() WC 8.7.0

public function get_item_response( $coupon ) {
	$coupon_object = new \WC_Coupon( $coupon->get_code() );
	return [
		'code'          => $coupon->get_code(),
		'discount_type' => $coupon_object ? $coupon_object->get_discount_type() : '',
		'totals'        => (object) $this->prepare_currency_response(
			[
				'total_discount'     => $this->prepare_money_response( $coupon->get_discount(), wc_get_price_decimals() ),
				'total_discount_tax' => $this->prepare_money_response( $coupon->get_discount_tax(), wc_get_price_decimals(), PHP_ROUND_HALF_DOWN ),
			]
		),
	];
}