AbstractMembershipEmail.php
23 hours ago
EmailDataTrait.php
1 year ago
NewOrderAdminNotification.php
2 years ago
NewOrderReceipt.php
2 years ago
RenewalOrderReceipt.php
2 years ago
SubscriptionAfterExpiredNotification.php
1 year ago
SubscriptionCancelledNotification.php
2 years ago
SubscriptionCompletedNotification.php
2 years ago
SubscriptionExpirationReminder.php
3 months ago
SubscriptionExpiredNotification.php
1 year ago
SubscriptionRenewalReminder.php
3 months ago
index.php
3 years ago
SubscriptionAfterExpiredNotification.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Membership\Emails; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Models\Customer\CustomerFactory; |
| 6 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionStatus; |
| 7 | use ProfilePress\Core\Membership\Repositories\SubscriptionRepository; |
| 8 | use ProfilePressVendor\Carbon\CarbonImmutable; |
| 9 | |
| 10 | class SubscriptionAfterExpiredNotification extends AbstractMembershipEmail |
| 11 | { |
| 12 | const ID = 'subscription_after_expired_reminder'; |
| 13 | |
| 14 | public function __construct() |
| 15 | { |
| 16 | add_action('ppress_daily_recurring_job', [$this, 'dispatch_email']); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @return void |
| 21 | */ |
| 22 | public function dispatch_email() |
| 23 | { |
| 24 | if ( ! apply_filters('ppress_subscription_after_expired_reminder_email_enabled', true)) return; |
| 25 | |
| 26 | if (ppress_get_setting(self::ID . '_email_enabled', 'on') !== 'on') return; |
| 27 | |
| 28 | $reminder_days = (int)apply_filters('ppress_' . self::ID . '_reminder_days', |
| 29 | ppress_get_setting(self::ID . '_reminder_days', '2', true) |
| 30 | ); |
| 31 | |
| 32 | $subDate = CarbonImmutable::now(wp_timezone())->subDays($reminder_days); |
| 33 | |
| 34 | $subscriptions = SubscriptionRepository::init()->retrieveBy([ |
| 35 | 'status' => [SubscriptionStatus::EXPIRED], |
| 36 | 'number' => 0, |
| 37 | 'date_column' => 'expiration_date', |
| 38 | 'start_date' => $subDate->startOfDay()->utc()->toDateTimeString(), |
| 39 | 'end_date' => $subDate->endOfDay()->utc()->toDateTimeString() |
| 40 | ]); |
| 41 | |
| 42 | if ( ! is_array($subscriptions) || empty($subscriptions)) return; |
| 43 | |
| 44 | foreach ($subscriptions as $subscription) { |
| 45 | |
| 46 | $placeholders_values = $this->get_subscription_placeholders_values($subscription); |
| 47 | |
| 48 | $subject = apply_filters('ppress_' . self::ID . '_email_subject', $this->parse_placeholders( |
| 49 | ppress_get_setting(self::ID . '_email_subject', esc_html__('Your subscription has expired.', 'wp-user-avatar'), true), |
| 50 | $placeholders_values, |
| 51 | $subscription |
| 52 | ), $subscription); |
| 53 | |
| 54 | $message = apply_filters('ppress_' . self::ID . '_email_content', $this->parse_placeholders( |
| 55 | ppress_get_setting(self::ID . '_email_content', $this->get_subscription_expired_content(), true), |
| 56 | $placeholders_values, |
| 57 | $subscription |
| 58 | ), $subscription); |
| 59 | |
| 60 | $recipient = apply_filters('ppress_' . self::ID . '_recipient', CustomerFactory::fromId($subscription->customer_id)->get_email(), $subscription); |
| 61 | |
| 62 | ppress_send_email($recipient, $subject, $message); |
| 63 | } |
| 64 | } |
| 65 | } |