Automattic\WooCommerce\StoreApi\Schemas\V1
OrderCouponSchema::get_item_response
Convert an order coupon to an object suitable for the response.
Method of the class: OrderCouponSchema{}
No Hooks.
Returns
array.
Usage
$OrderCouponSchema = new OrderCouponSchema(); $OrderCouponSchema->get_item_response( $coupon );
- $coupon(WC_Order_Item_Coupon) (required)
- Order coupon object.
OrderCouponSchema::get_item_response() OrderCouponSchema::get item response code WC 11.3.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 ),
]
),
];
}