1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
<?php
namespace AutomateWoo;
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * @class Action_Order_Resend_Email * @since 2.2 */ class Action_Order_Resend_Email extends Action {
/** * The data items required by the action. * * @var array */ public $required_data_items = [ 'order' ];
/** * Method to set the action's admin props. * * Admin props include: title, group and description. */ public function load_admin_details() { $this->title = __( 'Resend Order Email', 'automatewoo' ); $this->group = __( 'Order', 'automatewoo' ); $this->description = __( 'Please note that email tracking is not currently supported on this action.', 'automatewoo' ); }
/** * Method to load the action's fields. */ public function load_fields() {
$options = []; $mailer = WC()->mailer(); $available_emails = [ 'new_order', 'cancelled_order', 'failed_order', 'customer_processing_order', 'customer_completed_order', 'customer_on_hold_order', 'customer_invoice', 'customer_refunded_order', ]; $mails = $mailer->get_emails(); /** @var \WC_Email[] $mails */
if ( $mails ) { foreach ( $mails as $mail ) { if ( in_array( $mail->id, $available_emails, true ) ) { $title = $mail->get_title();
if ( ! $mail->is_customer_email() ) { $title .= ' - ' . __( 'Admin', 'automatewoo' ); } else { $title .= ' - ' . __( 'Customer', 'automatewoo' ); }
$options[ $mail->id ] = $title; } } }
$email = new Fields\Select( true ); $email->set_name( 'email' ); $email->set_title( __( 'Email', 'automatewoo' ) ); $email->set_required(); $email->set_options( $options );
$this->add_field( $email ); }
/** * Run the action. * * @throws \Exception When an error occurs. */ public function run() { $email_type = $this->get_option( 'email' ); $order = $this->workflow->data_layer()->get_order();
if ( ! $email_type || ! $order ) { return; }
do_action( 'woocommerce_before_resend_order_emails', $order );
// Ensure gateways are loaded in case they need to insert data into the emails WC()->payment_gateways(); WC()->shipping();
// Load mailer $mailer = WC()->mailer();
$mails = $mailer->get_emails(); if ( ! $mails ) { return; }
foreach ( $mails as $mail ) {
if ( $mail->id !== $email_type ) { continue; }
$mail->trigger( $order->get_id() );
do_action( 'woocommerce_after_resend_order_email', $order, $email_type );
// translators: %1$s Mail title, %2$d The Workflow ID $order->add_order_note( sprintf( __( '%1$s email notification sent by AutomateWoo workflow #%2$d', 'automatewoo' ), $mail->title, $this->workflow->get_id() ) ); } } }
|