PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.2.0
EmailKit – Email Customizer for WooCommerce & WP v1.2.0
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.2.0, at includes/Admin/Emails/Woocommerce/OrderOnHold.php

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