PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 2.3.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v2.3.1
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / actions / en_ticket_created.php

en_ticket_created.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 2.3.1, at includes/actions/en_ticket_created.php

163 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 global $wpscfunction, $wpdb,$current_user;
7
8 $from_name = get_option('wpsc_en_from_name','');
9 $from_email = get_option('wpsc_en_from_email','');
10 $reply_to = get_option('wpsc_en_reply_to','');
11 $ignore_emails = get_option('wpsc_en_ignore_emails','');
12
13 $wpsc_email_sending_method = get_option('wpsc_email_sending_method') ;
14
15 if ( !$from_name || !$from_email ) {
16 return;
17 }
18
19
20 $email_templates = get_terms([
21 'taxonomy' => 'wpsc_en',
22 'hide_empty' => false,
23 'orderby' => 'ID',
24 'order' => 'ASC',
25 'meta_query' => array(
26 'relation' => 'AND',
27 array(
28 'key' => 'type',
29 'value' => 'new_ticket',
30 'compare' => '='
31 ),
32 ),
33 ]);
34
35 $email_subject = get_option('wpsc_email_notification_subject');
36 $email_body = get_option('wpsc_email_notification_body');
37
38 foreach ($email_templates as $email) :
39
40 $conditions = get_term_meta($email->term_id,'conditions',true);
41 if( $wpscfunction->check_ticket_conditions($conditions,$ticket_id) ) :
42
43 $subject = $wpscfunction->replace_macro($email_subject['email_subject_' . $email->term_id], $ticket_id);
44 $subject = '['.get_option('wpsc_ticket_alice','').$ticket_id.'] '.stripslashes($subject);
45 $body = $wpscfunction->replace_macro(stripslashes($email_body['email_body_' . $email->term_id]), $ticket_id);
46 $recipients = get_term_meta($email->term_id,'recipients',true);
47 $extra_recipients = get_term_meta($email->term_id,'extra_recipients',true);
48
49 $email_addresses = array();
50 foreach ($recipients as $recipient) {
51 if(is_numeric($recipient)){
52 $agents = get_terms([
53 'taxonomy' => 'wpsc_agents',
54 'hide_empty' => false,
55 'meta_query' => array(
56 'relation' => 'AND',
57 array(
58 'key' => 'role',
59 'value' => $recipient,
60 'compare' => '='
61 ),
62 ),
63 ]);
64 foreach ($agents as $agent) {
65 $user_id = get_term_meta($agent->term_id,'user_id',true);
66 if($user_id){
67 $user = get_user_by('id',$user_id);
68 $email_addresses[] = $user->user_email;
69 }
70 }
71 } else {
72 switch ($recipient) {
73 case 'customer':
74 $do_not_notify = get_option('wpsc_do_not_notify_setting');
75 if( (!isset($_POST['notify_owner']) && $do_not_notify) || !$do_not_notify){
76 $customer_email = $wpscfunction->get_ticket_fields($ticket_id,'customer_email');
77 $email_addresses[] = $customer_email;
78 }
79 break;
80 case 'assigned_agent':
81 $email_addresses = array_merge($email_addresses,$wpscfunction->get_assigned_agent_emails($ticket_id));
82 break;
83 case 'extra_ticket_users' :
84 $extra_users = $wpscfunction->get_ticket_meta($ticket_id,'extra_ticket_users');
85 $email_addresses = array_merge($email_addresses, $extra_users);
86 break;
87 }
88 }
89 }
90 if(isset($extra_recipients[0]) && $extra_recipients[0] ) $email_addresses = array_merge($email_addresses,$extra_recipients);
91 $email_addresses = array_unique($email_addresses);
92
93 $email_addresses = apply_filters('wpsc_en_create_ticket_email_addresses',$email_addresses,$email,$ticket_id);
94 $email_addresses = array_values($email_addresses);
95
96 if ($ignore_emails) {
97 $ignore_emails = array_map('trim', $ignore_emails);
98 $email_addresses = array_map('trim', $email_addresses);
99 foreach ($ignore_emails as $ignore_email) {
100 foreach($email_addresses as $index => $email){
101 if(fnmatch($ignore_email, $email)){
102 unset($email_addresses[$index]);
103 }
104 }
105 }
106 }
107 $email_addresses = array_values($email_addresses);
108
109 $to = isset($email_addresses[0])? $email_addresses[0] : '';
110
111 if($to){
112 unset($email_addresses[0]);
113 }
114 else {
115 continue; // no email address found to send. So go to next foreach iteration.
116 }
117
118 $from_email = apply_filters('wpsc_create_ticket_from_email_headers',$from_email,$ticket_id);
119 $reply_to = apply_filters('wpsc_create_ticket_replyto_headers',$reply_to,$ticket_id);
120
121 $bcc = implode(',',$email_addresses);
122
123 $to = apply_filters('wpsc_create_ticket_to_email',$to,$email_addresses,$ticket_id);
124 $bcc = apply_filters('wpsc_create_ticket_bcc_emails',$bcc,$email_addresses,$ticket_id);
125
126 $args = array(
127 'ticket_id' => $ticket_id,
128 'from_email' => $from_email,
129 'reply_to' => $reply_to,
130 'email_subject' => $subject,
131 'email_body' => $body,
132 'to_email' => $to,
133 'bcc_email' => $bcc,
134 'date_created' => date("Y-m-d H:i:s"),
135 'mail_status' => 0,
136 'email_type' => 'ticket_created',
137
138 );
139
140 if($wpsc_email_sending_method){
141
142 $wpdb->insert( $wpdb->prefix . 'wpsc_email_notification',$args);
143
144 }else{
145
146 $headers = "From: {$from_name} <{$from_email}>\r\n";
147 $headers .= "Reply-To: {$reply_to}\r\n";
148 $email_addresses = explode(',',$bcc);
149 foreach ($email_addresses as $email_address) {
150 if(strlen($email_address)) $headers .= "BCC: {$email_address}\r\n";
151 }
152
153 $headers .= "Content-Type: text/html; charset=utf-8\r\n";
154
155 wp_mail($to, $subject, $body, $headers);
156 }
157
158 do_action('wpsc_after_ticket_created_mail',$ticket_id,$args);
159
160
161 endif;
162
163 endforeach;