PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.2
EmailKit – Email Customizer for WooCommerce & WP v1.5.2
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / Emails / Woocommerce / OrderOnHold.php

OrderOnHold.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.2, at includes/Admin/Emails/Woocommerce/OrderOnHold.php

153 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace EmailKit\Admin\Emails\Woocommerce;
3
4 use WP_Query;
5 use EmailKit\Admin\Emails\EmailLists;
6
7 defined("ABSPATH") || exit;
8
9 class OrderOnHold
10 {
11
12 private $db_query_class = null;
13
14 public function __construct()
15 {
16 $args = array(
17 'post_type' => 'emailkit',
18 'meta_query' => array(
19 array(
20 'key' => 'emailkit_template_type',
21 'value' => EmailLists::ORDER_ON_HOLD,
22 ),
23 array(
24 'key' => 'emailkit_template_status',
25 'value' => 'Active',
26 ),
27 ),
28 );
29
30
31 $this->db_query_class = new WP_Query($args);
32
33 if (isset($this->db_query_class->posts[0])) {
34 add_action('woocommerce_email', [$this, 'remove_woocommerce_emails']);
35 }
36
37 //
38 add_filter('woocommerce_order_status_pending_to_on-hold_notification', [$this, 'onHoldOrder'], 10, 2);
39 add_filter('woocommerce_order_status_failed_to_on-hold_notification', [$this, 'onHoldOrder'], 10, 2);
40 add_filter('woocommerce_order_status_cancelled_to_on-hold_notification', [$this, 'onHoldOrder'], 10, 2);
41 }
42
43 public function remove_woocommerce_emails($email_class)
44 {
45 remove_action('woocommerce_order_status_pending_to_on-hold_notification', array($email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger'));
46 remove_action('woocommerce_order_status_failed_to_on-hold_notification', array($email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger'));
47 remove_action('woocommerce_order_status_cancelled_to_on-hold_notification', array($email_class->emails['WC_Email_Customer_On_Hold_Order'], 'trigger'));
48 }
49
50 public function onHoldOrder($order_id, $order)
51 {
52
53
54 $query = $this->db_query_class;
55 $email = get_option('admin_email');
56 if (isset($query->posts[0])) {
57
58 $html = get_post_meta($query->posts[0]->ID, 'emailkit_template_content_html', true);
59
60 $woocommerce_currency_settings = get_woocommerce_currency_symbol();
61 $replacements = [];
62 foreach ($order->get_items() as $item_id => $item) {
63 $product = $item->get_product();
64 $id = $item['product_id'];
65 $product_name = $item['name'];
66 $item_qty = $item['quantity'];
67 $item_total = $item['total'];
68 $product_price = $product->get_price() * $item_qty;
69
70 // Use the currency symbol from the WooCommerce settings
71 $currency_symbol = $woocommerce_currency_settings;
72
73 // Format the product price with the currency symbol
74 $formatted_product_price = $currency_symbol . number_format($product_price, 2);
75
76 // Format the item total with the currency symbol
77 $formatted_item_total = $currency_symbol . number_format($item_total, 2);
78
79
80 $replacements[] = [$product_name, $item_qty, $formatted_item_total, $formatted_product_price];
81
82 }
83
84
85
86 $html = \EmailKit\Admin\Emails\Helpers\Utils::order_items_replace($html, $replacements);
87
88
89 $order = wc_get_order($order_id);
90
91 $shipping_first_name = $order->get_shipping_first_name();
92 $shipping_last_name = $order->get_shipping_last_name();
93 $shipping_full_name = $shipping_first_name . ' ' . $shipping_last_name;
94
95 $details = [
96 "{{order_id}}" => $order->get_id(),
97 "{{order_number}}" => $order->get_order_number(),
98 "{{order_status}}" => $order->get_status(),
99 "{{shipping_total}}" => wc_price( $order->get_shipping_total() ),
100 "{{order_subtotal}}" => wc_price( $order->get_subtotal()),
101 "{{order_currency}}" => $order->get_currency(),
102 "{{billing_phone}}" => $order->get_billing_phone(),
103 "{{shipping_tax_total}}" => wc_format_decimal($order->get_shipping_tax(), 2),
104 "{{order_date}}" => gmdate('Y-m-d H:i:s', strtotime(get_post($order->get_id())->post_date)),
105 "{{shipping_method}}" => $order->get_shipping_method(),
106 "{{payment_method}}" => $order->get_payment_method_title(),
107 "{{total}}" => wc_price($order->get_total(), 2),
108 "{{billing_name}}" => $order->get_formatted_billing_full_name(),
109 "{{billing_first_name}}" => $order->get_billing_first_name(),
110 "{{billing_last_name}}" => $order->get_billing_last_name(),
111 "{{billing_company}}" => $order->get_billing_company(),
112 "{{billing_address_1}}" => $order->get_billing_address_1(),
113 "{{billing_address_2}}" => $order->get_billing_address_2(),
114 "{{billing_city}}" => $order->get_billing_city(),
115 "{{billing_state}}" => $order->get_billing_state(),
116 "{{billing_postcode}}" => $order->get_billing_postcode(),
117 "{{billing_country}}" => $order->get_billing_country(),
118 "{{billing_email}}" => $order->get_billing_email(),
119 "{{shipping_name}}" => $shipping_full_name,
120 "{{shipping_first_name}}" => $shipping_first_name,
121 "{{shipping_last_name}}" => $shipping_last_name,
122 "{{shipping_company}}" => $order->get_shipping_company(),
123 "{{shipping_address_1}}" => $order->get_shipping_address_1(),
124 "{{shipping_address_2}}" => $order->get_shipping_address_2(),
125 "{{shipping_city}}" => $order->get_shipping_city(),
126 "{{shipping_state}}" => $order->get_shipping_state(),
127 "{{shipping_postcode}}" => $order->get_shipping_postcode(),
128 "{{shipping_country}}" => $order->get_shipping_country(),
129 "{{shipping_phone}}" => $order->get_shipping_phone(),
130 "{{customer_note}}" => $order->get_customer_note(),
131 "{{download_permissions}}" => $order->is_download_permitted() ? $order->is_download_permitted() : 0,
132 ];
133
134 $message = str_replace(array_keys($details), array_values($details), apply_filters('emailkit_shortcode_filter', $html));
135 $to = $order->get_billing_email();
136
137 $pre_header = get_post_meta($query->posts[0]->ID, 'emailkit_email_preheader', true);
138 $pre_header = !empty($pre_header) ? $pre_header : esc_html__("order has been received!", "emailkit");
139 $subject = str_replace(array_keys($details), array_values($details), get_post_meta($query->posts[0]->ID, 'emailkit_email_subject', true));
140 $subject = !empty($subject) ? $subject . ' - ' . $pre_header : esc_html__("Hi ", "emailkit") . esc_attr($order->get_billing_first_name() . " " . $order->get_billing_last_name()) . ", " . esc_html( "Your order #") . esc_attr($order_id) . esc_html(" has been received!") . " - " . $pre_header;
141
142
143
144 $headers = [
145 'From: ' . $email . "\r\n",
146 'Reply-To: ' . $email . "\r\n",
147 'Content-Type: text/html; charset=UTF-8',
148 ];
149
150 wp_mail($to, $subject, $message, $headers);
151 }
152 }
153 }