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

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

85 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 NoStock {
11
12 private $db_query_class = null;
13
14 public function __construct() {
15
16
17 $args = [
18 'post_type' => 'emailkit',
19 'meta_query' => [
20 [
21 'key' => 'emailkit_template_type',
22 'value' => EmailLists::NO_STOCK,
23 ],
24 [
25 'key' => 'emailkit_template_status',
26 'value' => 'Active',
27 ],
28 ],
29 ];
30
31
32 $this->db_query_class = new WP_Query($args);
33
34 if (isset($this->db_query_class->posts[0])) {
35 add_action('woocommerce_email', [$this, 'remove_woocommerce_emails']);
36 }
37
38 add_filter('woocommerce_no_stock_notification', [$this, 'stockNotification'], 10, 1);
39
40
41
42 }
43
44 public function remove_woocommerce_emails($email_class)
45 {
46
47 remove_action('woocommerce_no_stock_notification', array($email_class, 'no_stock'));
48 }
49
50 public function stockNotification($product)
51 {
52
53 $query = $this->db_query_class;
54 $email = get_option('admin_email');
55 if (isset($query->posts[0])) {
56
57 $html = get_post_meta($query->posts[0]->ID, 'emailkit_template_content_html', true);
58 $tbody = substr($html, strpos($html, '<tbody'));
59 $row = strpos($tbody, '</tbody>');
60 $rows = '';
61 $html = str_replace($row, $rows, $html);
62
63 // Stock details array for email
64 $details = Utils::woocommerce_stock_email_contents($product);
65
66 $message = str_replace(array_keys($details), array_values($details), apply_filters('emailkit_shortcode_filter', $html));
67 $to = get_option('admin_email');
68
69 $pre_header_template = get_post_meta($query->posts[0]->ID, 'emailkit_email_preheader', true);
70 $pre_header = str_replace(array_keys(Utils::transform_details_keys($details)), array_values(Utils::transform_details_keys($details)), $pre_header_template);
71 $pre_header = !empty($pre_header) ? $pre_header : esc_html__(' Stock Quantity Unavailable ', 'emailkit');
72 $subject_template = get_post_meta($query->posts[0]->ID, 'emailkit_email_subject', true);
73 $subject = str_replace(array_keys(Utils::transform_details_keys($details)), array_values(Utils::transform_details_keys($details)), $subject_template);
74 $subject = !empty($subject) ? $subject . ' - ' . $pre_header : $product->get_name() ." - " . esc_html__(' Out of Stock ', 'emailkit'). '-' . $pre_header;
75
76 $headers = [
77 'From: ' . $email . "\r\n",
78 'Reply-To: ' . $email . "\r\n",
79 'Content-Type: text/html; charset=UTF-8',
80 ];
81
82 wp_mail($to, $subject, $message, $headers);
83 }
84 }
85 }