Blocks
10 months ago
Coupons
1 month ago
Endpoints
2 months ago
Patterns
1 month ago
PersonalizationTags
3 days ago
ProductCollection
1 month ago
Templates
2 months ago
AutomationEmailContextProvider.php
1 month ago
AutomationEmailPreviewOrderProvider.php
1 month ago
BlockEmailContentDetector.php
1 month ago
Cli.php
2 weeks ago
DependencyNotice.php
10 months ago
EditorPageRenderer.php
1 week ago
EmailApiController.php
1 week ago
EmailEditor.php
2 months ago
EmailEditorPreviewEmail.php
9 months ago
Logger.php
10 months ago
MailPoetCssInliner.php
8 months ago
MailpoetCssInlinerFactory.php
1 year ago
PersonalizationTagManager.php
4 days ago
index.php
2 years ago
AutomationEmailPreviewOrderProvider.php
66 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\EmailEditor\Integrations\MailPoet; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WooCommerce\Helper as WooCommerceHelper; |
| 9 | |
| 10 | class AutomationEmailPreviewOrderProvider { |
| 11 | private WooCommerceHelper $wooCommerceHelper; |
| 12 | |
| 13 | public function __construct( |
| 14 | WooCommerceHelper $wooCommerceHelper |
| 15 | ) { |
| 16 | $this->wooCommerceHelper = $wooCommerceHelper; |
| 17 | } |
| 18 | |
| 19 | public function getOrder(): ?\WC_Order { |
| 20 | if (!class_exists(\WC_Order::class)) { |
| 21 | return null; |
| 22 | } |
| 23 | |
| 24 | try { |
| 25 | $order = $this->getExistingReviewableOrder(); |
| 26 | if ($order instanceof \WC_Order) { |
| 27 | return $order; |
| 28 | } |
| 29 | } catch (\Throwable $e) { |
| 30 | return null; |
| 31 | } |
| 32 | |
| 33 | return null; |
| 34 | } |
| 35 | |
| 36 | private function getExistingReviewableOrder(): ?\WC_Order { |
| 37 | $orders = $this->wooCommerceHelper->wcGetOrders([ |
| 38 | 'type' => 'shop_order', |
| 39 | 'status' => 'completed', |
| 40 | 'limit' => 10, |
| 41 | 'orderby' => 'date', |
| 42 | 'order' => 'DESC', |
| 43 | ]); |
| 44 | |
| 45 | if (!is_array($orders)) { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | foreach ($orders as $order) { |
| 50 | if (!$order instanceof \WC_Order) { |
| 51 | continue; |
| 52 | } |
| 53 | |
| 54 | if ($order->get_order_key() === '' || count($order->get_items()) === 0) { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | if ($this->wooCommerceHelper->wcOrderHasActionableReviewItems($order)) { |
| 59 | return $order; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return null; |
| 64 | } |
| 65 | } |
| 66 |