WC_Coupon::parse_short_info
Parse short info JSON into an array of coupon properties without validation.
Method of the class: WC_Coupon{}
No Hooks.
Returns
Array. ```php
Parsed coupon properties.
```php
`@type` int $id Coupon ID.
`@type` string $code Coupon code.
`@type` string $discount_type Discount type ('fixed_cart', 'percent', etc.).
`@type` float $amount Discount amount.
`@type` bool $free_shipping Whether free shipping is enabled.
Usage
$result = WC_Coupon::parse_short_info( $info ): array;
- $info(string) (required)
- JSON string as returned by
'get_short_info'.
WC_Coupon::parse_short_info() WC Coupon::parse short info code WC 10.6.2
private static function parse_short_info( string $info ): array {
$data = json_decode( $info, true );
if ( ! is_array( $data ) ) {
$data = array();
}
return array(
'id' => $data[0] ?? 0,
'code' => $data[1] ?? '',
'discount_type' => $data[2] ?? 'fixed_cart',
'amount' => (float) ( $data[3] ?? 0 ),
'free_shipping' => (bool) ( $data[4] ?? false ),
);
}