-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathVendorProductReview.php
233 lines (211 loc) · 7.6 KB
/
VendorProductReview.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
namespace WeDevs\Dokan\Emails;
use WC_Email;
/**
* Send email to vendor when a product is reviewed
*
* @since 3.9.2
*
* @class Dokan_Email_Vendor_Product_Review
*
* @author weDevs
*
* @extends WC_Email
*/
class VendorProductReview extends WC_Email {
/**
* Reply email
*
* @since 3.9.2
*
* @var string
*/
private $from_email;
/**
* Constructor.
*
* @since 3.9.2
*/
public function __construct() {
$this->id = 'dokan_contact_seller';
$this->title = __( 'Dokan Vendor Product Review', 'dokan-lite' );
$this->description = __( 'After a product has been reviewed, an email is sent to the vendor containing information about the review. The email may include details such as the reviewer’s name, the product’s name and description, the review rating, and the review text. The email may also contain a link to the review page where the vendor can view the review and respond to it if necessary.', 'dokan-lite' );
$this->template_html = 'emails/vendor-product-review.php';
$this->template_plain = 'emails/plain/vendor-product-review.php';
$this->template_base = DOKAN_DIR . '/templates/';
$this->placeholders = [
'{store_name}' => '',
'{product_name}' => '',
'{customer_name}' => '',
'{rating}' => '',
'{review_text}' => '',
'{review_link}' => '',
];
// Triggers for this email
add_action( 'wp_set_comment_status', [ $this, 'trigger' ], 35, 1 );
add_action( 'comment_post', [ $this, 'trigger' ], 35, 1 );
// Call parent constructor
parent::__construct();
// Other settings
$this->recipient = '[email protected]';
}
/**
* Get the email subject.
*
* @since 3.9.2
*
* @return string
*/
public function get_default_subject() {
return __( 'New Product Review Alert from {site_title}', 'dokan-lite' );
}
/**
* Get email heading.
*
* @since 3.9.2
*
* @return string
*/
public function get_default_heading() {
return __( 'New Product Review Alert From Your Store: {store_name} at - {site_title}', 'dokan-lite' );
}
/**
* Trigger this email.
*
* @since 3.9.2
*
* @param int $comment_id
*
* @return void
*/
public function trigger( $comment_id ) {
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return;
}
$comment = get_comment( $comment_id );
if ( ! $comment ) {
// the comment does not exist
return;
}
$product = wc_get_product( $comment->comment_post_ID );
if ( ! $product ) {
// the review is not for a product
return;
}
$this->setup_locale();
$this->from_email = get_option( 'admin_email' );
// get the vendor
$seller = dokan_get_vendor_by_product( $product->get_id() );
$this->placeholders['{store_name}'] = $seller->get_shop_name();
$this->placeholders['{product_name}'] = $product->get_title();
$this->placeholders['{customer_name}'] = $comment->comment_author;
$this->placeholders['{rating}'] = (int) get_comment_meta( $comment->comment_ID, 'rating', true );
$this->placeholders['{review_text}'] = wp_specialchars_decode( $comment->comment_content );
$this->placeholders['{review_link}'] = get_comment_link( $comment );
$this->send( $seller->get_email(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**
* Get the from address for outgoing emails.
*
* @since 3.9.2
*
* @return string
*/
public function get_from_address( $from_email = '' ) {
return $this->from_email;
}
/**
* Get content html.
*
* @since 3.9.2
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
[
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
'data' => $this->placeholders,
],
'dokan/', $this->template_base
);
}
/**
* Get content plain.
*
* @since 3.9.2
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
[
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
'data' => $this->placeholders,
],
'dokan/', $this->template_base
);
}
/**
* Initialize settings form fields.
*
* @since 3.9.2
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'dokan-lite' ), '<code>' . implode( '</code>, <code>', array_keys( $this->placeholders ) ) . '</code>' );
$this->form_fields = [
'enabled' => [
'title' => __( 'Enable/Disable', 'dokan-lite' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'dokan-lite' ),
'default' => 'yes',
],
'subject' => [
'title' => __( 'Subject', 'dokan-lite' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => $this->get_default_subject(),
],
'heading' => [
'title' => __( 'Email heading', 'dokan-lite' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => $this->get_default_heading(),
],
'additional_content' => [
'title' => __( 'Additional content', 'dokan-lite' ),
'description' => __( 'Text to appear below the main email content.', 'dokan-lite' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'dokan-lite' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => false,
],
'email_type' => [
'title' => __( 'Email type', 'dokan-lite' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'dokan-lite' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
],
];
}
}