class-wc-email-admin-payment-gateway-enabled.php
1 month ago
class-wc-email-cancelled-order.php
1 month ago
class-wc-email-customer-cancelled-order.php
1 month ago
class-wc-email-customer-completed-order.php
1 month ago
class-wc-email-customer-failed-order.php
1 month ago
class-wc-email-customer-fulfillment-created.php
1 month ago
class-wc-email-customer-fulfillment-deleted.php
1 month ago
class-wc-email-customer-fulfillment-updated.php
1 month ago
class-wc-email-customer-invoice.php
1 month ago
class-wc-email-customer-new-account.php
1 month ago
class-wc-email-customer-note.php
1 month ago
class-wc-email-customer-on-hold-order.php
1 month ago
class-wc-email-customer-partially-refunded-order.php
4 months ago
class-wc-email-customer-pos-completed-order.php
1 month ago
class-wc-email-customer-pos-refunded-order.php
1 month ago
class-wc-email-customer-processing-order.php
1 month ago
class-wc-email-customer-refunded-order.php
1 month ago
class-wc-email-customer-reset-password.php
1 month ago
class-wc-email-customer-review-request.php
1 month ago
class-wc-email-failed-order.php
1 month ago
class-wc-email-new-order.php
1 month ago
class-wc-email.php
1 month ago
class-wc-email-customer-invoice.php
270 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class WC_Email_Customer_Invoice file. |
| 4 | * |
| 5 | * @package WooCommerce\Emails |
| 6 | */ |
| 7 | |
| 8 | use Automattic\WooCommerce\Enums\OrderStatus; |
| 9 | use Automattic\WooCommerce\Utilities\FeaturesUtil; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; // Exit if accessed directly. |
| 13 | } |
| 14 | |
| 15 | if ( ! class_exists( 'WC_Email_Customer_Invoice', false ) ) : |
| 16 | |
| 17 | /** |
| 18 | * Order details email. |
| 19 | * |
| 20 | * An email sent to the customer via admin, that summarizes the details of their order. This was |
| 21 | * historically referred to as the 'invoice', and for backwards compatibility reasons that is still |
| 22 | * reflected in the class name (although on a user-level we have moved away from that nomenclature). |
| 23 | * |
| 24 | * @class WC_Email_Customer_Invoice |
| 25 | * @version 3.5.0 |
| 26 | * @package WooCommerce\Classes\Emails |
| 27 | * @extends WC_Email |
| 28 | */ |
| 29 | class WC_Email_Customer_Invoice extends WC_Email { |
| 30 | |
| 31 | /** |
| 32 | * Constructor. |
| 33 | */ |
| 34 | public function __construct() { |
| 35 | $this->id = 'customer_invoice'; |
| 36 | $this->customer_email = true; |
| 37 | $this->title = __( 'Order details', 'woocommerce' ); |
| 38 | $this->email_group = 'payments'; |
| 39 | $this->template_html = 'emails/customer-invoice.php'; |
| 40 | $this->template_plain = 'emails/plain/customer-invoice.php'; |
| 41 | $this->placeholders = array( |
| 42 | '{order_date}' => '', |
| 43 | '{order_number}' => '', |
| 44 | ); |
| 45 | |
| 46 | // Call parent constructor. |
| 47 | parent::__construct(); |
| 48 | |
| 49 | // Must be after parent's constructor which sets `email_improvements_enabled` property. |
| 50 | $this->description = $this->email_improvements_enabled |
| 51 | ? __( 'Manually send an email to your customers containing their order information and payment links', 'woocommerce' ) |
| 52 | : __( 'Order detail emails can be sent to customers containing their order information and payment links.', 'woocommerce' ); |
| 53 | |
| 54 | $this->manual = true; |
| 55 | |
| 56 | if ( $this->block_email_editor_enabled ) { |
| 57 | $this->title = __( 'Payment request', 'woocommerce' ); |
| 58 | $this->description = __( 'Manually send customers an email to review their order and complete payment.', 'woocommerce' ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get email subject. |
| 64 | * |
| 65 | * @param bool $paid Whether the order has been paid or not. |
| 66 | * @since 3.1.0 |
| 67 | * @return string |
| 68 | */ |
| 69 | public function get_default_subject( $paid = false ) { |
| 70 | return __( 'Details for order #{order_number} on {site_title}', 'woocommerce' ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get email heading. |
| 75 | * |
| 76 | * @param bool $paid Whether the order has been paid or not. |
| 77 | * @since 3.1.0 |
| 78 | * @return string |
| 79 | */ |
| 80 | public function get_default_heading( $paid = false ) { |
| 81 | return __( 'Details for order #{order_number}', 'woocommerce' ); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get email subject. |
| 86 | * |
| 87 | * @return string |
| 88 | */ |
| 89 | public function get_subject() { |
| 90 | if ( $this->object->has_status( array( OrderStatus::COMPLETED, OrderStatus::PROCESSING ) ) ) { |
| 91 | $subject = $this->get_option( 'subject_paid', $this->get_default_subject( true ) ); |
| 92 | |
| 93 | if ( $this->block_email_editor_enabled ) { |
| 94 | $subject = $this->personalizer->personalize_transactional_content( $subject, $this ); |
| 95 | } |
| 96 | |
| 97 | return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $subject ), $this->object, $this ); |
| 98 | } |
| 99 | |
| 100 | $subject = $this->get_option( 'subject', $this->get_default_subject() ); |
| 101 | |
| 102 | if ( $this->block_email_editor_enabled ) { |
| 103 | $subject = $this->personalizer->personalize_transactional_content( $subject, $this ); |
| 104 | } |
| 105 | |
| 106 | return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $subject ), $this->object, $this ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get email heading. |
| 111 | * |
| 112 | * @return string |
| 113 | */ |
| 114 | public function get_heading() { |
| 115 | if ( $this->object->has_status( wc_get_is_paid_statuses() ) ) { |
| 116 | $heading = $this->get_option( 'heading_paid', $this->get_default_heading( true ) ); |
| 117 | return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $heading ), $this->object, $this ); |
| 118 | } |
| 119 | |
| 120 | $heading = $this->get_option( 'heading', $this->get_default_heading() ); |
| 121 | return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $heading ), $this->object, $this ); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Default content to show below main email content. |
| 126 | * |
| 127 | * @since 3.7.0 |
| 128 | * @return string |
| 129 | */ |
| 130 | public function get_default_additional_content() { |
| 131 | return $this->email_improvements_enabled |
| 132 | ? __( 'Thanks again! If you need any help with your order, please contact us at {store_email}.', 'woocommerce' ) |
| 133 | : __( 'Thanks for using {site_url}!', 'woocommerce' ); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Trigger the sending of this email. |
| 138 | * |
| 139 | * @param int $order_id The order ID. |
| 140 | * @param WC_Order $order Order object. |
| 141 | */ |
| 142 | public function trigger( $order_id, $order = false ) { |
| 143 | $this->setup_locale(); |
| 144 | |
| 145 | if ( $order_id && ! is_a( $order, 'WC_Order' ) ) { |
| 146 | $order = wc_get_order( $order_id ); |
| 147 | } |
| 148 | |
| 149 | if ( is_a( $order, 'WC_Order' ) ) { |
| 150 | $this->object = $order; |
| 151 | $this->recipient = $this->object->get_billing_email(); |
| 152 | $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() ); |
| 153 | $this->placeholders['{order_number}'] = $this->object->get_order_number(); |
| 154 | } |
| 155 | |
| 156 | $this->send_if_recipient(); |
| 157 | |
| 158 | $this->restore_locale(); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Get content html. |
| 163 | * |
| 164 | * @return string |
| 165 | */ |
| 166 | public function get_content_html() { |
| 167 | return wc_get_template_html( |
| 168 | $this->template_html, |
| 169 | array( |
| 170 | 'order' => $this->object, |
| 171 | 'email_heading' => $this->get_heading(), |
| 172 | 'additional_content' => $this->get_additional_content(), |
| 173 | 'sent_to_admin' => false, |
| 174 | 'plain_text' => false, |
| 175 | 'email' => $this, |
| 176 | ) |
| 177 | ); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Get content plain. |
| 182 | * |
| 183 | * @return string |
| 184 | */ |
| 185 | public function get_content_plain() { |
| 186 | return wc_get_template_html( |
| 187 | $this->template_plain, |
| 188 | array( |
| 189 | 'order' => $this->object, |
| 190 | 'email_heading' => $this->get_heading(), |
| 191 | 'additional_content' => $this->get_additional_content(), |
| 192 | 'sent_to_admin' => false, |
| 193 | 'plain_text' => true, |
| 194 | 'email' => $this, |
| 195 | ) |
| 196 | ); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Initialise settings form fields. |
| 201 | */ |
| 202 | public function init_form_fields() { |
| 203 | /* translators: %s: list of placeholders */ |
| 204 | $placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' ); |
| 205 | $this->form_fields = array( |
| 206 | 'subject' => array( |
| 207 | 'title' => __( 'Subject', 'woocommerce' ), |
| 208 | 'type' => 'text', |
| 209 | 'desc_tip' => true, |
| 210 | 'description' => $placeholder_text, |
| 211 | 'placeholder' => $this->get_default_subject(), |
| 212 | 'default' => '', |
| 213 | ), |
| 214 | 'heading' => array( |
| 215 | 'title' => __( 'Email heading', 'woocommerce' ), |
| 216 | 'type' => 'text', |
| 217 | 'desc_tip' => true, |
| 218 | 'description' => $placeholder_text, |
| 219 | 'placeholder' => $this->get_default_heading(), |
| 220 | 'default' => '', |
| 221 | ), |
| 222 | 'subject_paid' => array( |
| 223 | 'title' => __( 'Subject (paid)', 'woocommerce' ), |
| 224 | 'type' => 'text', |
| 225 | 'desc_tip' => true, |
| 226 | 'description' => $placeholder_text, |
| 227 | 'placeholder' => $this->get_default_subject( true ), |
| 228 | 'default' => '', |
| 229 | ), |
| 230 | 'heading_paid' => array( |
| 231 | 'title' => __( 'Email heading (paid)', 'woocommerce' ), |
| 232 | 'type' => 'text', |
| 233 | 'desc_tip' => true, |
| 234 | 'description' => $placeholder_text, |
| 235 | 'placeholder' => $this->get_default_heading( true ), |
| 236 | 'default' => '', |
| 237 | ), |
| 238 | 'additional_content' => array( |
| 239 | 'title' => __( 'Additional content', 'woocommerce' ), |
| 240 | 'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text, |
| 241 | 'css' => 'width:400px; height: 75px;', |
| 242 | 'placeholder' => __( 'N/A', 'woocommerce' ), |
| 243 | 'type' => 'textarea', |
| 244 | 'default' => $this->get_default_additional_content(), |
| 245 | 'desc_tip' => true, |
| 246 | ), |
| 247 | 'email_type' => array( |
| 248 | 'title' => __( 'Email type', 'woocommerce' ), |
| 249 | 'type' => 'select', |
| 250 | 'description' => __( 'Choose which format of email to send.', 'woocommerce' ), |
| 251 | 'default' => 'html', |
| 252 | 'class' => 'email_type wc-enhanced-select', |
| 253 | 'options' => $this->get_email_type_options(), |
| 254 | 'desc_tip' => true, |
| 255 | ), |
| 256 | ); |
| 257 | if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) { |
| 258 | $this->form_fields['cc'] = $this->get_cc_field(); |
| 259 | $this->form_fields['bcc'] = $this->get_bcc_field(); |
| 260 | } |
| 261 | if ( $this->block_email_editor_enabled ) { |
| 262 | $this->form_fields['preheader'] = $this->get_preheader_field(); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | endif; |
| 268 | |
| 269 | return new WC_Email_Customer_Invoice(); |
| 270 |