WC_Coupon::parse_short_info
Parse short info JSON into an array of coupon properties without validation.
Метод класса: WC_Coupon{}
Хуков нет.
Возвращает
Массив. ```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.
Использование
$result = WC_Coupon::parse_short_info( $info ): array;
- $info(строка) (обязательный)
- JSON string as returned by
'get_short_info'.
Код WC_Coupon::parse_short_info() WC Coupon::parse short info WC 10.9.1
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 ),
);
}