1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
3
|
|
|
exit; // Exit if accessed directly. |
4
|
|
|
} |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Failed Renewal/Pre-Order Authentication Notification |
8
|
|
|
* |
9
|
|
|
* @extends WC_Stripe_Email_Failed_Authentication |
10
|
|
|
*/ |
11
|
|
|
class WC_Stripe_Email_Failed_Preorder_Authentication extends WC_Stripe_Email_Failed_Authentication { |
12
|
|
|
/** |
13
|
|
|
* Holds the message, which is entered by admins when sending the email. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $custom_message; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Constructor. |
21
|
|
|
* |
22
|
|
|
* @param WC_Email[] $email_classes All existing instances of WooCommerce emails. |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function __construct( $email_classes = array() ) { |
|
|
|
|
25
|
|
|
$this->id = 'failed_preorder_sca_authentication'; |
26
|
|
|
$this->title = __( 'Pre-order Payment Action Needed', 'woocommerce-gateway-stripe' ); |
27
|
|
|
$this->description = __( 'This is an order notification sent to the customer once a pre-order is complete, but additional payment steps are required.', 'woocommerce-gateway-stripe' ); |
28
|
|
|
$this->customer_email = true; |
29
|
|
|
|
30
|
|
|
$this->template_html = 'emails/failed-preorder-authentication.php'; |
31
|
|
|
$this->template_plain = 'emails/plain/failed-preorder-authentication.php'; |
32
|
|
|
$this->template_base = plugin_dir_path( WC_STRIPE_MAIN_FILE ) . 'templates/'; |
33
|
|
|
|
34
|
|
|
// Use the "authentication required" hook to add the correct, later hook. |
35
|
|
|
add_action( 'wc_gateway_stripe_process_payment_authentication_required', array( $this, 'trigger' ) ); |
36
|
|
|
|
37
|
|
|
if ( isset( $email_classes['WC_Pre_Orders_Email_Pre_Order_Available'] ) ) { |
38
|
|
|
$this->original_email = $email_classes['WC_Pre_Orders_Email_Pre_Order_Available']; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// We want all the parent's methods, with none of its properties, so call its parent's constructor, rather than my parent constructor. |
42
|
|
|
parent::__construct(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* When autnentication is required, this adds another action to `wc_pre_orders_pre_order_completed` |
47
|
|
|
* in order to send the authentication required email when the custom pre-orders message is available. |
48
|
|
|
* |
49
|
|
|
* @param WC_Order $order The order whose payment is failing. |
50
|
|
|
*/ |
51
|
|
|
public function trigger( $order ) { |
52
|
|
|
if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order->get_id() ) ) { |
53
|
|
|
if ( isset( $this->original_email ) ) { |
54
|
|
|
remove_action( 'wc_pre_order_status_completed_notification', array( $this->original_email, 'trigger' ), 10, 2 ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
add_action( 'wc_pre_orders_pre_order_completed', array( $this, 'send_email' ), 10, 2 ); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Triggers the email while also disconnecting the original Pre-Orders email. |
63
|
|
|
* |
64
|
|
|
* @param WC_Order $order The order that is being paid. |
65
|
|
|
* @param string $message The message, which should be added to the email. |
66
|
|
|
*/ |
67
|
|
|
public function send_email( $order, $message ) { |
68
|
|
|
$this->custom_message = $message; |
69
|
|
|
|
70
|
|
|
parent::trigger( $order ); |
|
|
|
|
71
|
|
|
|
72
|
|
|
// Restore the action of the original email for other bulk actions. |
73
|
|
|
if ( isset( $this->original_email ) ) { |
74
|
|
|
add_action( 'wc_pre_order_status_completed_notification', array( $this->original_email, 'trigger' ), 10, 2 ); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the default subject of the email (modifyable in settings). |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function get_default_subject() { |
84
|
|
|
return __( 'Payment authorization needed for pre-order {order_number}', 'woocommerce-gateway-stripe' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns the default heading of the email (modifyable in settings). |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function get_default_heading() { |
93
|
|
|
return __( 'Payment authorization needed for pre-order {order_number}', 'woocommerce-gateway-stripe' ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns the custom message, entered by the admin. |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function get_custom_message() { |
102
|
|
|
return $this->custom_message; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.