← All changes
|
app/Services/ShortCodeParser/Parsers/SubscriptionParser.php
+11
-2
1.5.4
→
1.6.5
View file →
| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace FluentCart\App\Services\ShortCodeParser\Parsers; |
| 4 | 4 | |
| 5 | 5 | use FluentCart\App\Helpers\Helper; |
| 6 | +use FluentCart\App\Services\DateTime\DateFormatter; | |
| 6 | 7 | use FluentCart\Framework\Support\Arr; |
| 7 | 8 | |
| 8 | 9 | class SubscriptionParser extends BaseParser |
| 9 | 10 | { |
| @@ -8,11 +9,19 @@ | ||
| 8 | 9 | class SubscriptionParser extends BaseParser |
| 9 | 10 | { |
| 10 | 11 | private $subscription; |
| 11 | 12 | |
| 13 | + /** | |
| 14 | + * Only used as the timezone context for DateFormatter — the order carries the | |
| 15 | + * user_tz captured at checkout. Null when the shortcode runs without one, in | |
| 16 | + * which case DateFormatter falls back to UTC. | |
| 17 | + */ | |
| 18 | + private $order; | |
| 19 | + | |
| 12 | 20 | public function __construct($data) |
| 13 | 21 | { |
| 14 | 22 | $this->subscription = Arr::get($data, 'subscription'); |
| 23 | + $this->order = Arr::get($data, 'order'); | |
| 15 | 24 | parent::__construct($data); |
| 16 | 25 | } |
| 17 | 26 | |
| 18 | 27 | public function parse($accessor = null, $code = null, $transformer = null): ?string |
| @@ -39,9 +48,9 @@ | ||
| 39 | 48 | case 'payment_info': |
| 40 | 49 | return wp_kses_post($subscription->payment_info); |
| 41 | 50 | case 'next_billing_date': |
| 42 | 51 | return $subscription->next_billing_date |
| 43 | - ? esc_html(date('M j, Y', strtotime($subscription->next_billing_date))) | |
| 52 | + ? esc_html(DateFormatter::format($subscription->next_billing_date, false, $this->order)) | |
| 44 | 53 | : __('N/A', 'fluent-cart'); |
| 45 | 54 | case 'bill_times': |
| 46 | 55 | return $subscription->bill_times |
| 47 | 56 | ? esc_html($subscription->bill_times) |
| @@ -51,9 +60,9 @@ | ||
| 51 | 60 | case 'trial_days': |
| 52 | 61 | return esc_html($subscription->trial_days ?: '0'); |
| 53 | 62 | case 'expire_at': |
| 54 | 63 | return $subscription->expire_at |
| 55 | - ? esc_html(date('M j, Y', strtotime($subscription->expire_at))) | |
| 64 | + ? esc_html(DateFormatter::format($subscription->expire_at, false, $this->order)) | |
| 56 | 65 | : __('Never', 'fluent-cart'); |
| 57 | 66 | default: |
| 58 | 67 | return Arr::get((array) $subscription, $accessor, ''); |
| 59 | 68 | } |