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 / NoStock.php

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

97 lines 2.8 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 defined( 'ABSPATH' ) || exit;
8
9 class NoStock {
10
11 private $db_query_class = null;
12
13 public function __construct() {
14
15
16 $args = [
17 'post_type' => 'emailkit',
18 'meta_query' => [
19 [
20 'key' => 'emailkit_template_type',
21 'value' => EmailLists::NO_STOCK,
22 ],
23 [
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 add_filter('woocommerce_no_stock_notification', [$this, 'stockNotification'], 10, 1);
38
39
40
41 }
42
43 public function remove_woocommerce_emails($email_class)
44 {
45
46 remove_action('woocommerce_no_stock_notification', array($email_class, 'no_stock'));
47 }
48
49 public function stockNotification($product)
50 {
51
52 $query = $this->db_query_class;
53 $email = get_option('admin_email');
54 if (isset($query->posts[0])) {
55
56 $html = get_post_meta($query->posts[0]->ID, 'emailkit_template_content_html', true);
57 $tbody = substr($html, strpos($html, '<tbody'));
58 $row = strpos($tbody, '</tbody>');
59 $rows = '';
60 $html = str_replace($row, $rows, $html);
61
62
63 $details = [
64
65 "{{stock_status}}" => $product->get_stock_status(),
66 "{{product_name}}" => $product->get_name(),
67 "{{stock_quantity}}" => $product->get_stock_quantity(),
68 "{{status}}" => $product->get_status(),
69 "{{product_id}}" => $product->get_id(),
70 "{{short_description}}" => $product->get_short_description(),
71 "{{product_price}}" => $product->get_price(),
72 "{{manage_stock}}" => $product->get_manage_stock(),
73 "{{sku}}" => $product->get_sku(),
74 "{{low_stock_amount}}" => $product->get_low_stock_amount(),
75 "{{backorders}}" => $product->get_backorders(),
76 "{{site_name}}" => get_bloginfo('name'),
77
78 ];
79
80 $message = str_replace(array_keys($details), array_values($details), apply_filters('emailkit_shortcode_filter', $html));
81 $to = get_option('admin_email');
82
83 $pre_header = get_post_meta($query->posts[0]->ID, 'emailkit_email_preheader', true);
84 $pre_header = !empty($pre_header) ? $pre_header : esc_html__(' Stock Quantity Unavailable ', 'emailkit');
85 $subject = str_replace(array_keys($details), array_values($details), get_post_meta($query->posts[0]->ID, 'emailkit_email_subject', true));
86 $subject = !empty($subject) ? $subject . ' - ' . $pre_header : $product->get_name() ." - " . esc_html__(' Out of Stock ', 'emailkit'). '-' . $pre_header;
87
88 $headers = [
89 'From: ' . $email . "\r\n",
90 'Reply-To: ' . $email . "\r\n",
91 'Content-Type: text/html; charset=UTF-8',
92 ];
93
94 wp_mail($to, $subject, $message, $headers);
95 }
96 }
97 }