CardIcons
1 year ago
CouponsController.php
7 months ago
IppFunctions.php
1 year ago
MobileMessagingHandler.php
2 years ago
OrderActionsRestController.php
3 months ago
OrderAttributionBlocksController.php
1 year ago
OrderAttributionController.php
5 months ago
OrderNoteGroup.php
3 months ago
OrderStatusRestController.php
5 months ago
PaymentInfo.php
10 months ago
PointOfSaleEmailHandler.php
3 months ago
PointOfSaleOrderUtil.php
4 weeks ago
TaxesController.php
3 years ago
PointOfSaleEmailHandler.php
69 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PointOfSaleEmailHandler class file. |
| 4 | */ |
| 5 | |
| 6 | declare( strict_types = 1 ); |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal\Orders; |
| 9 | |
| 10 | use Automattic\WooCommerce\Internal\RegisterHooksInterface; |
| 11 | use WC_Abstract_Order; |
| 12 | |
| 13 | /** |
| 14 | * Suppresses standard automated emails for orders paid at POS. |
| 15 | * |
| 16 | * POS has its own email templates (customer_pos_completed_order, |
| 17 | * customer_pos_refunded_order) that are sent automatically or via REST API. |
| 18 | * This handler prevents the standard transactional emails from firing |
| 19 | * when an order is paid at POS, regardless of where it was created. |
| 20 | * |
| 21 | * @internal Just for internal use. |
| 22 | * |
| 23 | * @since 10.6.0 |
| 24 | */ |
| 25 | class PointOfSaleEmailHandler implements RegisterHooksInterface { |
| 26 | |
| 27 | /** |
| 28 | * Standard email IDs to suppress for POS-paid orders. |
| 29 | */ |
| 30 | private const SUPPRESSED_EMAIL_IDS = array( |
| 31 | 'customer_processing_order', |
| 32 | 'customer_completed_order', |
| 33 | 'customer_on_hold_order', |
| 34 | 'customer_refunded_order', |
| 35 | 'customer_partially_refunded_order', |
| 36 | 'new_order', |
| 37 | ); |
| 38 | |
| 39 | /** |
| 40 | * Register hooks and filters. |
| 41 | */ |
| 42 | public function register(): void { |
| 43 | foreach ( self::SUPPRESSED_EMAIL_IDS as $email_id ) { |
| 44 | add_filter( 'woocommerce_email_enabled_' . $email_id, array( $this, 'maybe_suppress_email' ), 10, 2 ); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Suppress email if the order was paid at POS. |
| 50 | * |
| 51 | * @param bool $enabled Whether the email is enabled. |
| 52 | * @param mixed $order The order object (or null). |
| 53 | * @return bool False if the order was paid at POS, original value otherwise. |
| 54 | * |
| 55 | * @internal For exclusive usage within this class, backwards compatibility not guaranteed. |
| 56 | */ |
| 57 | public function maybe_suppress_email( bool $enabled, $order ): bool { |
| 58 | if ( ! $order instanceof WC_Abstract_Order ) { |
| 59 | return $enabled; |
| 60 | } |
| 61 | |
| 62 | if ( PointOfSaleOrderUtil::is_order_paid_at_pos( $order ) ) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | return $enabled; |
| 67 | } |
| 68 | } |
| 69 |