Emails
2 months ago
Integrations
2 months ago
MultichannelMarketing
2 years ago
TransactionalEmails
10 months ago
WooCommerceBookings
1 month ago
WooCommerceSubscriptions
2 months ago
CouponPreProcessor.php
2 months ago
Emails.php
8 months ago
Helper.php
1 month ago
MailPoetTask.php
2 years ago
NonPersistablePreviewData.php
1 month ago
OrderAttributionFields.php
1 month ago
OrderAttributionRevenueReader.php
2 weeks ago
OrderAttributionWriter.php
1 month ago
RandomCouponCodeGenerator.php
2 months ago
Settings.php
1 year ago
SubscriberEngagement.php
3 years ago
Subscription.php
2 months ago
Tracker.php
2 years ago
TransactionalEmailHooks.php
1 year ago
TransactionalEmails.php
1 year ago
WooSystemInfo.php
1 month ago
WooSystemInfoController.php
1 year ago
index.php
3 years ago
SubscriberEngagement.php
56 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\WooCommerce; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\SubscriberEntity; |
| 9 | use MailPoet\Subscribers\SubscribersRepository; |
| 10 | use WC_Order; |
| 11 | |
| 12 | class SubscriberEngagement { |
| 13 | |
| 14 | /** @var Helper */ |
| 15 | private $woocommerceHelper; |
| 16 | |
| 17 | /** @var SubscribersRepository */ |
| 18 | private $subscribersRepository; |
| 19 | |
| 20 | public function __construct( |
| 21 | Helper $woocommerceHelper, |
| 22 | SubscribersRepository $subscribersRepository |
| 23 | ) { |
| 24 | $this->woocommerceHelper = $woocommerceHelper; |
| 25 | $this->subscribersRepository = $subscribersRepository; |
| 26 | } |
| 27 | |
| 28 | public function updateSubscriberEngagement($orderId): void { |
| 29 | $order = $this->woocommerceHelper->wcGetOrder($orderId); |
| 30 | if (!$order instanceof WC_Order) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | $subscriber = $this->subscribersRepository->findOneBy(['email' => $order->get_billing_email()]); |
| 35 | if (!$subscriber instanceof SubscriberEntity) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $this->subscribersRepository->maybeUpdateLastEngagement($subscriber); |
| 40 | } |
| 41 | |
| 42 | public function updateSubscriberLastPurchase($orderId): void { |
| 43 | $order = $this->woocommerceHelper->wcGetOrder($orderId); |
| 44 | if (!$order instanceof WC_Order) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | $subscriber = $this->subscribersRepository->findOneBy(['email' => $order->get_billing_email()]); |
| 49 | if (!$subscriber instanceof SubscriberEntity) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | $this->subscribersRepository->maybeUpdateLastPurchaseAt($subscriber); |
| 54 | } |
| 55 | } |
| 56 |