Completed
Push — master ( 500373...3722c0 )
by Claudio
25s queued 10s
created

includes/emails/class-wc-email-customer-note.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Class WC_Email_Customer_Note file.
4
 *
5
 * @package WooCommerce\Emails
6
 */
7
8 1
if ( ! defined( 'ABSPATH' ) ) {
9
	exit; // Exit if accessed directly.
10
}
11
12 1
if ( ! class_exists( 'WC_Email_Customer_Note', false ) ) :
13
14
	/**
15
	 * Customer Note Order Email.
16
	 *
17
	 * Customer note emails are sent when you add a note to an order.
18
	 *
19
	 * @class       WC_Email_Customer_Note
20
	 * @version     3.5.0
21
	 * @package     WooCommerce/Classes/Emails
22
	 * @extends     WC_Email
23
	 */
24
	class WC_Email_Customer_Note extends WC_Email {
25
26
		/**
27
		 * Customer note.
28
		 *
29
		 * @var string
30
		 */
31
		public $customer_note;
32
33
		/**
34
		 * Constructor.
35
		 */
36 1 View Code Duplication
		public function __construct() {
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
37 1
			$this->id             = 'customer_note';
38 1
			$this->customer_email = true;
39 1
			$this->title          = __( 'Customer note', 'woocommerce' );
40 1
			$this->description    = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
41 1
			$this->template_html  = 'emails/customer-note.php';
42 1
			$this->template_plain = 'emails/plain/customer-note.php';
43 1
			$this->placeholders   = array(
44
				'{order_date}'   => '',
45
				'{order_number}' => '',
46
			);
47
48
			// Triggers.
49 1
			add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) );
50
51
			// Call parent constructor.
52 1
			parent::__construct();
53
		}
54
55
		/**
56
		 * Get email subject.
57
		 *
58
		 * @since  3.1.0
59
		 * @return string
60
		 */
61 1
		public function get_default_subject() {
62 1
			return __( 'Note added to your {site_title} order from {order_date}', 'woocommerce' );
63
		}
64
65
		/**
66
		 * Get email heading.
67
		 *
68
		 * @since  3.1.0
69
		 * @return string
70
		 */
71 1
		public function get_default_heading() {
72 1
			return __( 'A note has been added to your order', 'woocommerce' );
73
		}
74
75
		/**
76
		 * Trigger.
77
		 *
78
		 * @param array $args Email arguments.
79
		 */
80
		public function trigger( $args ) {
81
			$this->setup_locale();
82
83
			if ( ! empty( $args ) ) {
84
				$defaults = array(
85
					'order_id'      => '',
86
					'customer_note' => '',
87
				);
88
89
				$args = wp_parse_args( $args, $defaults );
90
91
				$order_id      = $args['order_id'];
92
				$customer_note = $args['customer_note'];
93
94
				if ( $order_id ) {
95
					$this->object = wc_get_order( $order_id );
96
97
					if ( $this->object ) {
98
						$this->recipient                      = $this->object->get_billing_email();
99
						$this->customer_note                  = $customer_note;
100
						$this->placeholders['{order_date}']   = wc_format_datetime( $this->object->get_date_created() );
101
						$this->placeholders['{order_number}'] = $this->object->get_order_number();
102
					}
103
				}
104
			}
105
106
			if ( $this->is_enabled() && $this->get_recipient() ) {
107
				$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
108
			}
109
110
			$this->restore_locale();
111
		}
112
113
		/**
114
		 * Get content html.
115
		 *
116
		 * @return string
117
		 */
118 View Code Duplication
		public function get_content_html() {
119
			return wc_get_template_html(
120
				$this->template_html,
121
				array(
122
					'order'              => $this->object,
123
					'email_heading'      => $this->get_heading(),
124
					'additional_content' => $this->get_additional_content(),
125
					'customer_note'      => $this->customer_note,
126
					'sent_to_admin'      => false,
127
					'plain_text'         => false,
128
					'email'              => $this,
129
				)
130
			);
131
		}
132
133
		/**
134
		 * Get content plain.
135
		 *
136
		 * @return string
137
		 */
138 View Code Duplication
		public function get_content_plain() {
139
			return wc_get_template_html(
140
				$this->template_plain,
141
				array(
142
					'order'              => $this->object,
143
					'email_heading'      => $this->get_heading(),
144
					'additional_content' => $this->get_additional_content(),
145
					'customer_note'      => $this->customer_note,
146
					'sent_to_admin'      => false,
147
					'plain_text'         => true,
148
					'email'              => $this,
149
				)
150
			);
151
		}
152
153
		/**
154
		 * Default content to show below main email content.
155
		 *
156
		 * @since 3.7.0
157
		 * @return string
158
		 */
159 1
		public function get_default_additional_content() {
160 1
			return __( 'Thanks for reading.', 'woocommerce' );
161
		}
162
	}
163
164
endif;
165
166
return new WC_Email_Customer_Note();
167