PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.6.2
EmailKit – Email Customizer for WooCommerce & WP v1.6.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 / BackOrder.php

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

83 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Admin\Emails\Woocommerce;
4
5 use WP_Query;
6 use EmailKit\Admin\Emails\EmailLists;
7 use EmailKit\Admin\Emails\Helpers\Utils;
8 defined( 'ABSPATH' ) || exit;
9
10 class BackOrder {
11
12 private $db_query_class = null;
13 public function __construct() {
14
15 $args = [
16 'post_type' => 'emailkit',
17 'meta_query' => [
18 [
19 'key' => 'emailkit_template_type',
20 'value' => EmailLists::BACK_ORDER,
21 ],
22 [
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 add_filter('woocommerce_product_on_backorder_notification', [$this, 'stockNotification'], 10, 1);
37 }
38
39
40 public function remove_woocommerce_emails($email_class)
41 {
42
43 remove_action('woocommerce_product_on_backorder_notification', [$email_class, 'backorder']);
44 }
45
46 public function stockNotification($product)
47 {
48
49
50 $query = $this->db_query_class;
51 $email = get_option('admin_email');
52 if (isset($query->posts[0])) {
53 $html = get_post_meta($query->posts[0]->ID, 'emailkit_template_content_html', true);
54 $tbody = substr($html, strpos($html, '<tbody'));
55 $row = strpos($tbody, '</tbody>');
56 $rows = '';
57 $html = str_replace($row, $rows, $html);
58
59 // Stock details array for email
60 $details = Utils::woocommerce_stock_email_contents($product['product']);
61
62 $message = str_replace(array_keys($details), array_values($details), apply_filters('emailkit_shortcode_filter', $html));
63 $to = get_option('admin_email');
64
65 $subject_template = get_post_meta($query->posts[0]->ID, 'emailkit_email_subject', true);
66 $subject = str_replace(array_keys(Utils::transform_details_keys($details)), array_values(Utils::transform_details_keys($details)), $subject_template);
67 $pre_header_template = get_post_meta($query->posts[0]->ID, 'emailkit_email_preheader', true);
68 $pre_header = str_replace(array_keys(Utils::transform_details_keys($details)), array_values(Utils::transform_details_keys($details)), $pre_header_template);
69 $pre_header = !empty($pre_header) ? $pre_header : esc_html__(' Product is on backorder', 'emailkit');
70 $subject = !empty($subject) ? $subject . ' - ' . $pre_header : $product['product']->get_name() . " - " .esc_html__(' is on backorder', 'emailkit').' - ' . $pre_header;
71
72
73
74 $headers = [
75 'From: ' . $email . "\r\n",
76 'Reply-To: ' . $email . "\r\n",
77 'Content-Type: text/html; charset=UTF-8',
78 ];
79
80 wp_mail($to, $subject, $message, $headers);
81 }
82 }
83 }