-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-wc-stock-order-email.php
146 lines (119 loc) · 4.59 KB
/
class-wc-stock-order-email.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
if (! defined('ABSPATH')) {
exit;
} // Exit if accessed directly
class WC_Stock_Order_Email extends WC_Email
{
public function __construct()
{
$this->id = 'wc_stock_order';
$this->title = 'Comanda per cada magatzem';
$this->description = "Envia un email a cada magatzem amb els productes de la comanda que cal reservar";
// these are the default heading and subject lines that can be overridden using the settings
$this->heading = '[{site_title}][{warehouse}] Nova comanda de client ({order_number}) - {order_date}';
$this->subject = '[{site_title}][{warehouse}] Nova comanda de client ({order_number}) - {order_date}';
parent::__construct();
}
public function trigger($order, $warehouse_code, $warehouse_data)
{
global $wpdb;
$table_name = "{$wpdb->prefix}wc_warehouse";
$this->object = $order;
$s = $wpdb->get_row($wpdb->prepare("SELECT * from $table_name where code='%s'", $warehouse_code));
//error_log(date('d-m-Y, H:i:s') . ": ". print_r($s, true)."\n", 3, 'aaaa.log');
// if (!$s) {
// return;
// }
$this->warehouse_code = $warehouse_code;
$this->warehouse_name = stripslashes($s->name);
$this->warehouse_email = stripslashes($s->email);
$this->warehouse_data = $warehouse_data;
// replace variables in the subject/headings
$this->find[] = '{site_title}';
$this->replace[] = get_bloginfo( 'name' );
$this->find[] = '{warehouse}';
$this->replace[] = $this->warehouse_name;
$this->find[] = '{order_date}';
$this->replace[] = wc_format_datetime( $this->object->get_date_created() );
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number();
// if (! $this->is_enabled() || $this->warehouse_email === '' || is_null($this->warehouse_email)) {
// return;
// }
$this->send($this->warehouse_email, $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
}
/**
* get_content_html function.
*
* @since 0.1
* @return string
*/
public function get_content_html()
{
ob_start();
echo "<h3>" . _e( 'Order number:', 'woocommerce' ) . " " . $this->object->get_order_number() . "</h3>";
echo "<ul>";
foreach ($this->warehouse_data as $row) {
echo "<li>" . $row['sku'] . " - " . $row['name'] . ": " . $row['quantity'] . " unitats</li>";
}
echo "</ul>";
return ob_get_clean();
}
/**
* get_content_plain function.
*
* @since 0.1
* @return string
*/
public function get_content_plain()
{
ob_start();
echo _e( 'Order number:', 'woocommerce' ) . " " . $this->object->get_order_number() . "\n";
echo "\n";
foreach ($this->warehouse_data as $row) {
echo $row['sku'] . " - " . $row['name'] . ": " . $row['quantity'] . " unitats\n";
}
return ob_get_clean();
}
/**
* Initialize Settings Form Fields
*
* @since 2.0
*/
public function init_form_fields()
{
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable this email notification',
'default' => 'yes'
),
'subject' => array(
'title' => 'Subject',
'type' => 'text',
'description' => sprintf('Deixar en blanc per fer servir el valor per defecte: <code>%s</code>.', $this->subject),
'placeholder' => '',
'default' => ''
),
'heading' => array(
'title' => 'Email Heading',
'type' => 'text',
'description' => sprintf(__('Deixar en blanc per fer servir el valor per defecte: <code>%s</code>.'), $this->heading),
'placeholder' => '',
'default' => ''
),
'email_type' => array(
'title' => 'Email type',
'type' => 'select',
'description' => "Format d'enviament.",
'default' => 'html',
'class' => 'email_type',
'options' => array(
'plain' => __('Text Pla', 'woocommerce'),
'html' => __('HTML', 'woocommerce')
)
)
);
}
}