PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services / 5.0.3
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services v5.0.3
8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 8.5.0 8.4.9 All 531 releases
chatbot / functions.php

functions.php in WPBot – AI ChatBot for Live Support, Lead Generation, AI Services 5.0.3, at functions.php

1,967 lines 104.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @param $type
4 * Display wpwBot Icon ball
5 */
6 if (!defined('ABSPATH')) exit; // Exit if accessed directly
7 add_action('wp_footer', 'wp_chatbot_load_footer_html');
8 add_action( 'admin_footer', 'qc_style_for_hide_iframe');
9 function qc_style_for_hide_iframe(){
10 ?>
11 <script>
12 jQuery( document ).ready(function() {
13 setInterval(function(){
14 if(document.querySelector('.wp-block-legacy-widget__edit-preview-iframe')){
15 document.querySelector('.wp-block-legacy-widget__edit-preview-iframe').addEventListener("load", ev => {
16 jQuery('.wp-block-legacy-widget__edit-preview-iframe').contents().find('#wp-chatbot-chat-container').hide();
17 });
18
19 }
20 }, 500);
21 });
22 </script>
23 <?php
24 }
25 function wp_chatbot_load_footer_html(){
26 if ( get_option('disable_wp_chatbot') != 1 && wp_chatbot_load_controlling() === true) {
27
28 ?>
29 <style>
30 <?php if(get_option('wp_chatbot_custom_css')!="") {
31 echo sanitize_text_field(get_option('wp_chatbot_custom_css'));
32 }
33 ?>
34 </style>
35
36 <?php if (get_option('qcld_wb_chatbot_change_bg') == 1) {
37 if (get_option('qcld_wb_chatbot_board_bg_path') != "") {
38 $qcld_wb_chatbot_board_bg_path = get_option('qcld_wb_chatbot_board_bg_path');
39 } else {
40 $qcld_wb_chatbot_board_bg_path = QCLD_wpCHATBOT_IMG_URL . 'background/background.png';
41 }
42 ?>
43 <style>
44 .wp-chatbot-container {
45 background-image: url(<?php echo esc_url($qcld_wb_chatbot_board_bg_path); ?>) !important;
46 }
47 </style>
48 <?php }
49 $wp_chatbot_enable_rtl = "";
50 if (get_option('enable_wp_chatbot_rtl') == '1') {
51 $wp_chatbot_enable_rtl .= "wp-chatbot-rtl";
52 }
53 $wp_chatbot_enable_mobile_screen = "";
54 // if (get_option('enable_wp_chatbot_mobile_full_screen')==1) {
55 $wp_chatbot_enable_mobile_screen .= "wp-chatbot-mobile-full-screen";
56 // }
57 ?>
58 <div id="wp-chatbot-chat-container" class="<?php echo esc_attr($wp_chatbot_enable_rtl .' '.$wp_chatbot_enable_mobile_screen); ?>">
59 <div id="wp-chatbot-integration-container">
60 <div class="wp-chatbot-integration-button-container">
61 <?php if (get_option('enable_wp_chatbot_skype_floating_icon') == 1) { ?>
62 <a href="skype:<?php echo esc_attr(get_option('enable_wp_chatbot_skype_id')); ?>?chat"><span
63 class="inetegration-skype-btn" title="<?php esc_attr_e('Skype', 'wpchatbot'); ?>"> </span></a>
64 <?php } ?>
65 <?php if (get_option('enable_wp_chatbot_floating_whats') == 1) { ?>
66 <a href="<?php echo esc_url('https://api.whatsapp.com/send?phone=' . get_option('qlcd_wp_chatbot_whats_num')); ?>"
67 target="_blank"><span class="intergration-whats"
68 title="<?php esc_html_e('WhatsApp', 'wpchatbot'); ?>"></span></a>
69 <?php } ?>
70 <?php if (get_option('enable_wp_chatbot_floating_viber') == 1) { ?>
71 <a href="<?php echo esc_url('https://live.viber.com/#/' . get_option('qlcd_wp_chatbot_viber_acc')); ?>"
72 target="_blank"><span class="intergration-viber"
73 title="<?php esc_html_e('Viber', 'wpchatbot'); ?>"></span></a>
74 <?php } ?>
75 <?php if (get_option('enable_wp_chatbot_floating_phone') == 1 && get_option('qlcd_wp_chatbot_phone') != "") { ?>
76 <a href="tel:<?php echo esc_attr(get_option('qlcd_wp_chatbot_phone')); ?>"><span
77 class="intergration-phone"
78 title="<?php esc_html_e('Phone', 'wpchatbot'); ?>"> </span></a>
79 <?php } ?>
80 <?php if (get_option('enable_wp_chatbot_floating_link') == 1 && get_option('qlcd_wp_chatbot_weblink') != "") { ?>
81 <a href="<?php echo esc_url(get_option('qlcd_wp_chatbot_weblink')); ?>" target="_blank"><span
82 class="intergration-weblink" title="<?php esc_html_e('Web Link', 'wpchatbot'); ?>"></span></a>
83 <?php } ?>
84 </div>
85 </div>
86 <?php
87 //Get wpcommerce cart
88
89 $qcld_wb_chatbot_theme = get_option('qcld_wb_chatbot_theme');
90 if (file_exists(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/style.css')) {
91 wp_register_style('qcld-wp-chatbot-style', plugins_url(basename(plugin_dir_path(__FILE__)) . '/templates/' . $qcld_wb_chatbot_theme . '/style.css', basename(__FILE__)), '', QCLD_wpCHATBOT_VERSION, 'screen');
92 wp_enqueue_style('qcld-wp-chatbot-style');
93 }
94 if (file_exists(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/template.php')) {
95 require_once(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/template.php');
96 } else {
97 echo "<h2>" . __('No wpWBot Theme Found!', 'wpchatbot') . "</h2>";
98 }
99 ?>
100 <?php
101 if (get_option('disable_wp_chatbot_notification') != 1) {
102 ?>
103 <div id="wp-chatbot-notification-container" class="wp-chatbot-notification-container">
104 <div class="wp-chatbot-notification-controller">
105 <span class="wp-chatbot-notification-close">
106 <?php esc_html_e('X', 'wpchatbot'); ?>
107 </span>
108 </div>
109 <?php
110 $testingTip="";
111 if (get_option('wp_chatbot_agent_image') == "custom-agent.png") {
112 $wp_chatbot_custom_agent_path = get_option('wp_chatbot_custom_agent_path');
113 } else if (get_option('wp_chatbot_agent_image') != "custom-agent.png") {
114 $wp_chatbot_custom_agent_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image');
115 } else {
116 $wp_chatbot_custom_agent_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png';
117 }
118 ?>
119 <div class="wp-chatbot-notification-agent-profile">
120 <div class="wp-chatbot-notification-widget-avatar" ><img
121 src="<?php echo esc_attr($wp_chatbot_custom_agent_path); ?>" alt=""></div>
122 <div class="wp-chatbot-notification-welcome"><?php echo wp_kses_post(wpb_randmom_message_handle(maybe_unserialize(get_option('qlcd_wp_chatbot_welcome')))) . ' <strong>' . esc_html(get_option('qlcd_wp_chatbot_host')) . '</strong>'; ?></div>
123 </div>
124 <?php
125 //update_option('qlcd_wp_chatbot_notifications','Welcome to WpBot');
126 $notifications = qcld_wb_chatbot_func_str_replace(wp_kses_post(maybe_unserialize(get_option('qlcd_wp_chatbot_notifications'))));
127
128 ?>
129
130 <div class="wp-chatbot-notification-message"><?php echo esc_html($notifications[0]); ?></div>
131 </div>
132 <?php } ?>
133 <!--wp-chatbot-board-container-->
134 <div id="wp-chatbot-ball" class="">
135 <div class="wp-chatbot-ball">
136 <div class="wp-chatbot-ball-animator wp-chatbot-ball-animation-switch"></div>
137 <?php
138 if (get_option('wp_chatbot_icon') == "custom.png") {
139 $wp_chatbot_custom_icon_path = (!empty(get_option('wp_chatbot_custom_icon_path')) && !is_404(get_option('wp_chatbot_custom_icon_path'))) ? get_option('wp_chatbot_custom_icon_path') : QCLD_wpCHATBOT_IMG_URL . 'icon-1.png';
140
141 } else if (get_option('wp_chatbot_icon') != "custom.png") {
142 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_icon');
143 } else {
144 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom.png';
145 }
146 ?>
147 <img src="<?php echo esc_url($wp_chatbot_custom_icon_path); ?>"
148 alt="wpChatIcon" qcld_agent="<?php echo esc_url($wp_chatbot_custom_icon_path); ?>" >
149
150 </div>
151 </div>
152 <?php
153 $fb_app_id = get_option('qlcd_wp_chatbot_fb_app_id');
154 $fb_page_id = get_option('qlcd_wp_chatbot_fb_page_id');
155 $fb_mgs_color = get_option('qlcd_wp_chatbot_fb_color') != '' ? get_option('qlcd_wp_chatbot_fb_color') : '#0084ff';
156 $fb_mgs_in = get_option('qlcd_wp_chatbot_fb_in_msg') != '' ? get_option('qlcd_wp_chatbot_fb_in_msg') : 'You are welcome';
157 $fb_mgs_out = get_option('qlcd_wp_chatbot_fb_out_msg') != '' ? get_option('qlcd_wp_chatbot_fb_out_msg') : 'You are not logged in';
158 if (get_option('enable_wp_chatbot_messenger') == 1 && get_option('enable_wp_chatbot_messenger_floating_icon') == 1) {
159 ?>
160 <!-- wp-chatbot-board-container-->
161 <script>
162
163 window.fbAsyncInit = function () {
164 FB.init({
165 appId: '<?php echo esc_js($fb_app_id); ?>',
166 autoLogAppEvents: true,
167 xfbml: true,
168 version: 'v2.12'
169 });
170 };
171
172 (function (d, s, id) {
173 var js, fjs = d.getElementsByTagName(s)[0];
174 if (d.getElementById(id)) return;
175 js = d.createElement(s);
176 js.id = id;
177 js.src = 'https://connect.facebook.net/en_US/sdk.js';
178 fjs.parentNode.insertBefore(js, fjs);
179 }(document, 'script', 'facebook-jssdk'));
180 </script>
181 <div class="fb-customerchat"
182 page_id="<?php echo esc_attr($fb_page_id); ?>"
183 greeting_dialog_display="hide"
184 theme_color="<?php echo esc_attr($fb_mgs_color); ?>"
185 logged_in_greeting="<?php echo esc_attr($fb_mgs_in); ?>"
186 logged_out_greeting="<?php echo esc_attr($fb_mgs_out); ?>"></div>
187 <?php
188 }
189 ?>
190 <!--container-->
191 <!--wp-chatbot-ball-wrapper-->
192 </div>
193
194 <?php
195
196 if ( get_transient( 'bot_clear_cache' ) ) {
197 echo '<script type="text/javascript">var wpbot_clear_cache = 1 </script>';
198 delete_transient( 'bot_clear_cache' );
199 }
200
201 }else{
202 ?>
203 <script>
204 var openingHourIsFn = 1;
205 </script>
206 <?php
207 }
208 }
209 //wp_chatbot load control handler.
210 function wp_chatbot_load_controlling(){
211 $wp_chatbot_load = true;
212
213
214 if (get_option('wp_chatbot_show_pages') == 'off') {
215 $wp_chatbot_select_pages = unserialize(get_option('wp_chatbot_show_pages_list'));
216 if (is_page() && !empty($wp_chatbot_select_pages)) {
217
218 if (in_array(get_the_ID(), $wp_chatbot_select_pages) == true) {
219
220 $wp_chatbot_load = true;
221 } else {
222 $wp_chatbot_load = false;
223 }
224
225 }
226
227 if(function_exists('is_shop')){
228 if (is_shop() || is_cart() || is_checkout() || 'product' == get_post_type()) {
229 $wp_chatbot_load = false;
230 }
231 }
232
233 }
234 if (get_option('wp_chatbot_show_wpcommerce') == 'off') {
235
236 }
237 //load wpwbot shortcode template and prevent default wpwbot from footer.
238 if (is_page()) {
239 $page_id = get_the_ID();
240 $page = get_post($page_id);
241 if (has_shortcode($page->post_content, 'wpwbot')) {
242 $wp_chatbot_load = false;
243 }
244 }
245
246 $post_list = maybe_unserialize(get_option('wp_chatbot_exclude_post_list'));
247
248 if( is_array( $post_list ) && in_array(get_post_type(), $post_list)){
249 $wp_chatbot_load = false;
250 }
251 if (wp_chatbot_is_mobile() && get_option('disable_wp_chatbot_on_mobile') == 1) {
252 $wp_chatbot_load = false;
253 }
254
255 if (get_option('wp_chatbot_show_home_page') == 'off' && is_home()) {
256 $wp_chatbot_load = false;
257 }
258
259 if (get_option('wp_chatbot_show_posts') == 'off' && 'post' == get_post_type()) {
260 $wp_chatbot_load = false;
261 }
262
263 if(is_admin()){
264 $wp_chatbot_load = false;
265 }
266 return $wp_chatbot_load;
267 }
268 //checking Devices
269 function wp_chatbot_is_mobile(){
270 if (isset($_SERVER['HTTP_USER_AGENT'])) {
271 $useragent = $_SERVER['HTTP_USER_AGENT'];
272 if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($useragent, 0, 4))) {
273 return true;
274 } else {
275 return false;
276 }
277 }
278 }
279 //Checking wpwbot opening hour
280 function wp_chatbot_check_opening_hours(){
281 $curent_day=strtolower(date('l',strtotime(current_time( 'mysql' ))));
282 $current_time=date('H:i',strtotime(current_time( 'mysql')));
283 $is_wpwbot_open =false;
284 if(get_option('wpwbot_hours')) {
285 $wpwbot_times = wp_kses_post(unserialize(get_option('wpwbot_hours')));
286 if (isset($wpwbot_times[$curent_day])) {
287 $day_times = $wpwbot_times[$curent_day];
288 if (!empty($day_times)) {
289 foreach ($day_times as $day_time) {
290 if(strtotime($current_time) > strtotime($day_time[0]) && strtotime($current_time) < strtotime($day_time[1]) ){
291 $is_wpwbot_open=true;
292 }
293 }
294 }
295 }
296 }
297 return $is_wpwbot_open;
298 }
299 //wpwBot shortcode.
300 add_shortcode('wpwbot', 'wp_chatbot_short_code');
301 function wp_chatbot_short_code($atts = []){
302 ob_start();
303 wp_chatbot_shortcode_dom($atts);
304 $content = ob_get_clean();
305 return $content;
306 }
307 function wp_chatbot_shortcode_dom($atts){
308 //Defaults & Set Parameters for shortcode
309 extract(shortcode_atts(
310 array(
311 'template' => '01',
312 ), $atts
313 ));
314 ?>
315 <style>
316 <?php if(get_option('wp_chatbot_custom_css')!=""){echo sanitize_text_field(get_option('wp_chatbot_custom_css')); } ?>
317 </style>
318 <?php if (get_option('qcld_wb_chatbot_change_bg') == 1) {
319 if (get_option('qcld_wb_chatbot_board_bg_path') != "") {
320 $qcld_wb_chatbot_board_bg_path = get_option('qcld_wb_chatbot_board_bg_path');
321 } else {
322 $qcld_wb_chatbot_board_bg_path = QCLD_wpCHATBOT_IMG_URL . 'background/background.png';
323 }
324 ?>
325 <style>
326 .wp-chatbot-container {
327 background: url(<?php echo esc_url($qcld_wb_chatbot_board_bg_path) ;?>) no-repeat top right !important;
328 }
329 </style>
330 <?php }
331 $wp_chatbot_enable_rtl = "";
332 if (get_option('enable_wp_chatbot_rtl')) {
333 $wp_chatbot_enable_rtl .= "wp-chatbot-rtl";
334 }
335 ?>
336 <div id="wp-chatbot-chat-container" class="<?php echo esc_attr($wp_chatbot_enable_rtl); ?>">
337 <?php
338 //Get wpcommerce cart
339
340 $qcld_wb_chatbot_theme = 'template-' . $template;
341 if (file_exists(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/style.css')) {
342 wp_register_style('qcld-wp-chatbot-style', plugins_url(basename(plugin_dir_path(__FILE__)) . '/templates/' . $qcld_wb_chatbot_theme . '/style.css', basename(__FILE__)), '', QCLD_wpCHATBOT_VERSION, 'screen');
343 wp_enqueue_style('qcld-wp-chatbot-style');
344 }
345 if (file_exists(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/template.php')) {
346 require_once(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/template.php');
347 } else {
348 echo "<h2>" . __('No wpWBot Theme Found!', 'wpchatbot') . "</h2>";
349 }
350 ?>
351 <?php if (get_option('disable_wp_chatbot') != 1): ?>
352 <div id="wp-chatbot-notification-container" class="wp-chatbot-notification-container">
353 <div class="wp-chatbot-notification-controller"> <span class="wp-chatbot-notification-close">X</span> </div>
354 <?php
355 if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") {
356 $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path');
357 } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") {
358 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image');
359 } else {
360 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png';
361 }
362 ?>
363 <div class="wp-chatbot-notification-agent-profile">
364 <div class="wp-chatbot-notification-widget-avatar"><img
365 src="<?php echo esc_url($wp_chatbot_custom_icon_path); ?>" alt=""></div>
366 <div class="wp-chatbot-notification-welcome"><?php echo wp_kses_post(wpb_randmom_message_handle(maybe_unserialize(get_option('qlcd_wp_chatbot_welcome')))) . ' <strong>' . esc_html(get_option('qlcd_wp_chatbot_host')) . '</strong>'; ?></div>
367 </div>
368 <div class="wp-chatbot-notification-message"><?php echo wp_kses_post(wpb_randmom_message_handle(maybe_unserialize(get_option('qlcd_wp_chatbot_notifications')))); ?></div>
369 </div>
370 <!--wp-chatbot-board-container-->
371 <div id="wp-chatbot-ball" class="">
372 <div class="wp-chatbot-ball">
373 <div class="wp-chatbot-ball-animator wp-chatbot-ball-animation-switch"></div>
374 <?php
375 if (get_option('wp_chatbot_custom_icon_path') != "" && get_option('wp_chatbot_icon') == "custom.png") {
376 $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_icon_path');
377 } else if (get_option('wp_chatbot_custom_icon_path') != "" && get_option('wp_chatbot_icon') != "custom.png") {
378 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_icon');
379 } else {
380 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom.png';
381 }
382 ?>
383 <img src="<?php echo esc_url($wp_chatbot_custom_icon_path); ?>"
384 alt="wpChatIcon"> <!--<span class="wp-chatbot-ball-cart-items"><?php echo $cart_items_number; ?></span>--> </div>
385 </div>
386 <!-- wp-chatbot-board-container-->
387 <?php endif; ?>
388 <!--container-->
389 <!--wp-chatbot-ball-wrapper-->
390 </div>
391 <?php } ?>
392 <?php
393 //Create shortcode for wpwBot for pages.
394 add_shortcode('wpbot-page', 'wp_chatbot_page_short_code');
395 function wp_chatbot_page_short_code(){
396 ob_start();
397 wp_chatbot_page_dom();
398 $content = ob_get_clean();
399 return $content;
400 }
401 function wp_chatbot_page_dom(){ ?>
402 <style>
403 <?php if(get_option('wp_chatbot_custom_css')!=""){echo sanitize_text_field(get_option('wp_chatbot_custom_css')); } ?>
404 </style>
405 <?php
406 //Get wpcommerce cart
407
408 $qcld_wb_chatbot_theme = get_option('qcld_wb_chatbot_theme');
409 $wp_chatbot_enable_rtl = "";
410 if (get_option('enable_wp_chatbot_rtl') == 1) {
411 $wp_chatbot_enable_rtl .= "wp-chatbot-rtl";
412 }
413 if (file_exists(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/shortcode.php')) {
414 require_once(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/shortcode.php');
415 } else {
416 echo "<h2>" . __('No WPBot ShortCode Theme Found!', 'wpchatbot') . "</h2>";
417 }
418 }
419 //shortcode for wpWBot mobile app
420 add_shortcode('wpwbot_app', 'wp_chatbot_mobile_app_short_code');
421 function wp_chatbot_mobile_app_short_code(){ ?>
422 <style>
423 <?php if(get_option('wp_chatbot_custom_css')!=""){echo sanitize_text_field(get_option('wp_chatbot_custom_css')); } ?>
424 </style>
425 <?php if (get_option('qcld_wb_chatbot_change_bg') == 1) {
426 if (get_option('qcld_wb_chatbot_board_bg_path') != "") {
427 $qcld_wb_chatbot_board_bg_path = get_option('qcld_wb_chatbot_board_bg_path');
428 } else {
429 $qcld_wb_chatbot_board_bg_path = QCLD_wpCHATBOT_IMG_URL . 'background/background.png';
430 }
431 ?>
432 <style>
433 .wp-chatbot-container {
434 background: url(<?php echo esc_url($qcld_wb_chatbot_board_bg_path) ;?>) no-repeat top right !important;
435 }
436 </style>
437 <?php }
438 $wp_chatbot_enable_rtl = "";
439 if (get_option('enable_wp_chatbot_rtl') == '1') {
440 $wp_chatbot_enable_rtl .= "wp-chatbot-rtl";
441 }
442 ?>
443 <div id="wp-chatbot-chat-app-shortcode-container" class="<?php echo esc_attr($wp_chatbot_enable_rtl); ?>">
444 <?php
445 // keep traking app template.
446 $template_app = 'yes';
447 //Get wpcommerce cart
448
449 //Handling shortcode enqeue and remove features part.
450 define('wpCOMMERCE', true);
451 wp_enqueue_script('jquery');
452
453
454 wp_enqueue_script('wc-address-i18n');
455 wp_enqueue_script('wc-country-select');
456
457
458 // add the action
459 if (isset($_GET['from']) && $_GET['from'] == 'app') {
460 if (!isset($_COOKIE['from_app'])) {
461 setcookie('from_app', 'yes', time() + 3600);
462 }
463 }
464 $qcld_wb_chatbot_theme = get_option('qcld_wb_chatbot_theme');
465 if (file_exists(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/template.php')) {
466 require_once(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . '/templates/' . $qcld_wb_chatbot_theme . '/template.php');
467 } else {
468 echo "<h2>" . __('No WPBot Theme Found!', 'wpchatbot') . "</h2>";
469 }
470 ?>
471 </div>
472 <?php
473 }
474
475 /**
476 * wpwBot Search keyword product
477 */
478 add_action('wp_ajax_qcld_wb_chatbot_keyword', 'qcld_wb_chatbot_keyword');
479 add_action('wp_ajax_nopriv_qcld_wb_chatbot_keyword', 'qcld_wb_chatbot_keyword');
480 function qcld_wb_chatbot_keyword(){
481 $keyword = sanitize_text_field($_POST['keyword']);
482 $product_per_page = get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10;
483 if (get_option('qlcd_wp_chatbot_search_option') == 'standard') {
484 $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title');
485 $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC');
486 //Merging all query together.
487 $argu_params = array(
488 'post_type' => 'product',
489 'post_status' => 'publish',
490 'posts_per_page' => $product_per_page,
491 'orderby' => $product_orderby,
492 'order' => $product_order,
493 's' => $keyword,
494 );
495 /******
496 *WP Query Operation to get products.*
497 *******/
498 $product_query = new WP_Query($argu_params);
499 $product_num = $product_query->post_count;
500 //Getting total product number by string.
501 $total_argu = array('post_type' => 'product', 's' => $keyword, 'posts_per_page' => 100);
502 $total_query = new WP_Query($total_argu);
503 $total_product_num = $total_query->post_count;
504 $html = '<div class="wp-chatbot-products-area">';
505 $_pf = new WC_Product_Factory();
506 //repeating the products
507 if ($product_num > 0) {
508 $html .= '<ul class="wp-chatbot-products">';
509 while ($product_query->have_posts()) : $product_query->the_post();
510 $product = $_pf->get_product(get_the_ID());
511 if (wp_chatbot_product_controlling(get_the_ID()) == true) {
512 $html .= '<li class="wp-chatbot-product">';
513 $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" wp-chatbot-pid= "' . get_the_ID() . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '">';
514 $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '
515 <div class="wp-chatbot-product-summary">
516 <div class="wp-chatbot-product-table">
517 <div class="wp-chatbot-product-table-cell">
518 <h3 class="wp-chatbot-product-title">' . $product->post->post_title . '</h3>
519 <div class="price">' . $product->get_price_html() . '</div>';
520 $html .= ' </div>
521 </div>
522 </div></a>
523 </li>';
524 }
525 endwhile;
526 wp_reset_postdata();
527 $html .= '</ul>';
528 if ($total_product_num > $product_per_page && $product_per_page > 0 ) {
529 $html .= '<p style="text-align: center"><button type="button" id="wp-chatbot-loadmore" data-offset="' . $product_per_page . '" data-search-type="product" data-search-term="' . $keyword . '" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_load_more')))) . ' <span id="wp-chatbot-loadmore-loader"></span></button> </p>';
530 }
531 }
532 $html .= '</div>';
533 } else if (get_option('qlcd_wp_chatbot_search_option') == 'advanced') {
534 $result = wpwBot_Search::factory()->search($keyword);
535 $products = $result['products'];
536 $product_num = count($result['products']);
537 $total_product_num = $result['total_products'];
538 $more_product_ids = implode(",", $result['more_ids']);
539 $html = '<div class="wp-chatbot-products-area">';
540 $_pf = new WC_Product_Factory();
541 //repeating the products
542 if ($product_num > 0) {
543 $html .= '<ul class="wp-chatbot-products">';
544 foreach ($products as $product) {
545 if (wp_chatbot_product_controlling($product->get_id()) == true) {
546 $html .= '<li class="wp-chatbot-product">';
547 $html .= '<a target="_blank" href="' . get_permalink($product->get_id()) . '" wp-chatbot-pid= "' . $product->get_id() . '" title="' . esc_attr($product->get_title()) . '">';
548 $html .= get_the_post_thumbnail($product->get_id(), 'shop_catalog') . '
549 <div class="wp-chatbot-product-summary">
550 <div class="wp-chatbot-product-table">
551 <div class="wp-chatbot-product-table-cell">
552 <h3 class="wp-chatbot-product-title">' . $product->get_title() . '</h3>
553 <div class="price">' . $product->get_price_html() . '</div>';
554 $html .= ' </div></div></div></a></li>';
555 }
556 }
557 $html .= '</ul>';
558 if ($total_product_num > $product_per_page && $product_per_page > 0) {
559 $html .= '<p style="text-align: center"><button type="button" id="wp-chatbot-loadmore" data-offset="' . $product_per_page . '" data-search-type="product" data-search-term="' . $more_product_ids . '" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_load_more')))) . ' <span id="wp-chatbot-loadmore-loader"></span></button> </p>';
560 }
561 }
562 $html .= '</div>';
563 }
564 $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page);
565 wp_send_json($response);
566
567 }
568 /**
569 * wpwBot Categories
570 */
571 add_action('wp_ajax_qcld_wb_chatbot_category', 'qcld_wb_chatbot_category');
572 add_action('wp_ajax_nopriv_qcld_wb_chatbot_category', 'qcld_wb_chatbot_category');
573 function qcld_wb_chatbot_category(){
574 $category_type="common";
575 if (get_option('wp_chatbot_show_parent_category') != "") {
576 $terms = get_terms('product_cat', array('parent' => 0, 'hide_empty' => true, 'fields' => 'all'));
577
578 } else {
579 $terms = get_terms('product_cat', array('hide_empty' => true, 'fields' => 'all'));
580 }
581 $html = "";
582 foreach ($terms as $term) {
583 $child_terms=get_terms('product_cat', array('parent' => $term->term_id, 'hide_empty' => true, 'fields' => 'all'));
584 if(get_option('wp_chatbot_show_sub_category')==1 && count($child_terms) >0){
585 $category_type="hasChilds";
586 }
587 $html .= '<span class="qcld-chatbot-product-category" data-category-type="' . $category_type . '" data-category-slug="' . $term->slug . '" data-category-id="' . $term->term_id . '">' . $term->name . '</span>';
588 }
589 wp_send_json($html);
590
591 }
592 /**
593 * wpwBot Sub categories
594 */
595 add_action('wp_ajax_qcld_wb_chatbot_sub_category', 'qcld_wb_chatbot_sub_category');
596 add_action('wp_ajax_nopriv_qcld_wb_chatbot_sub_category', 'qcld_wb_chatbot_sub_category');
597 function qcld_wb_chatbot_sub_category(){
598 $parent_id = stripslashes($_POST['parent_id']);
599 $terms = get_terms('product_cat', array('parent' => $parent_id, 'hide_empty' => true, 'fields' => 'all'));
600 $html = "";
601 foreach ($terms as $term) {
602 $html .= '<span class="qcld-chatbot-product-category" data-category-type="common" data-category-slug="' . $term->slug . '" data-category-id="' . $term->term_id . '">' . $term->name . '</span>';
603 }
604 wp_send_json($html);
605
606 }
607 /**
608 * wpwBot category product
609 */
610 add_action('wp_ajax_qcld_wb_chatbot_category_products', 'qcld_wb_chatbot_category_products');
611 add_action('wp_ajax_nopriv_qcld_wb_chatbot_category_products', 'qcld_wb_chatbot_category_products');
612 function qcld_wb_chatbot_category_products(){
613 $category_id = stripslashes($_POST['category']);
614 $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10);
615 $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title');
616 $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC');
617 //Merging all query together.
618 $argu_params = array(
619 'post_type' => 'product',
620 'post_status' => 'publish',
621 'ignore_sticky_posts' => 1,
622 'orderby' => $product_orderby,
623 'order' => $product_order,
624 'posts_per_page' => $product_per_page,
625 'tax_query' => array(
626 array(
627 'taxonomy' => 'product_cat',
628 'field' => 'term_id',
629 'terms' => $category_id,
630 'operator' => 'IN'
631 )
632 )
633 );
634 /******
635 *WP Query Operation to get products.*
636 *******/
637 $product_query = new WP_Query($argu_params);
638 $product_num = $product_query->post_count;
639 //Getting total product number by string.
640 $total_argu = array(
641 'post_type' => 'product',
642 'post_status' => 'publish',
643 'posts_per_page' => 100,
644 'tax_query' => array(
645 array(
646 'taxonomy' => 'product_cat',
647 'field' => 'term_id',
648 'terms' => $category_id,
649 'operator' => 'IN'
650 )
651 )
652 );
653 $total_query = new WP_Query($total_argu);
654 $total_product_num = $total_query->post_count;
655 $_pf = new WC_Product_Factory();
656 //repeating the products
657 $html = '';
658 if ($product_num > 0) {
659 $html .= '<div class="wp-chatbot-products-area">';
660 $html .= '<ul class="wp-chatbot-products">';
661 while ($product_query->have_posts()) : $product_query->the_post();
662 $product = $_pf->get_product(get_the_ID());
663 //$qcld_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'shop_thumbnail' );
664 $html .= '<li class="wp-chatbot-product">';
665 $html .= '<a class="wp-chatbot-product-url" wp-chatbot-pid= "' . get_the_ID() . '" target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->get_title() ? $product->get_title() : get_the_ID()) . '">';
666 $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '
667 <div class="wp-chatbot-product-summary">
668 <div class="wp-chatbot-product-table">
669 <div class="wp-chatbot-product-table-cell">
670 <h3 class="wp-chatbot-product-title">' . $product->get_title() . '</h3>
671 <div class="price">' . $product->get_price_html() . '</div>';
672 $html .= ' </div>
673 </div>
674 </div></a>
675 </li>';
676 endwhile;
677 wp_reset_postdata();
678 $html .= '</ul>';
679 if ($total_product_num > $product_per_page && $product_per_page >0) {
680 $html .= '<p style="text-align: center"><button type="button" id="wp-chatbot-loadmore" data-offset="' . $product_per_page . '" data-search-type="category" data-search-term="' . $category_id . '" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_load_more')))) . ' <span id="wp-chatbot-loadmore-loader"></span></button> </p>';
681 }
682 $html .= '</div>';
683 } else {
684 $html = '';
685 }
686 $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page);
687 wp_send_json($response);
688 }
689 /**
690 * wpwBot latest, featured, recent product
691 */
692 add_action('wp_ajax_qcld_wb_chatbot_featured_products', 'qcld_wb_chatbot_featured_products');
693 add_action('wp_ajax_nopriv_qcld_wb_chatbot_featured_products', 'qcld_wb_chatbot_featured_products');
694 function qcld_wb_chatbot_featured_products(){
695 $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10);
696 $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title');
697 $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC');
698 //get featured products query.
699 $argu_params = array('post_status' => 'publish',
700 'posts_per_page' => $product_per_page,
701 'post_type' => 'product',
702 'post_status' => 'publish',
703 'tax_query' => array(array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured'))
704 );
705 /******
706 *WP Query Operation to get products.*
707 *******/
708 $product_query = new WP_Query($argu_params);
709 $product_num = $product_query->post_count;
710 //Getting total product number by string.
711 $total_argu = array('post_status' => 'publish',
712 'posts_per_page' => 100,
713 'post_type' => 'product',
714 'post_status' => 'publish',
715 'tax_query' => array(array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured',),)
716 );
717 $total_query = new WP_Query($total_argu);
718 $total_product_num = $total_query->post_count;
719 $html = '<div class="wp-chatbot-products-area">';
720 $_pf = new WC_Product_Factory();
721 //repeating the products
722 if ($product_num > 0) {
723 //$html .= '<p>sdf sdfdsf : '.$asdfdf.'</p>';
724 $html .= '<ul class="wp-chatbot-products">';
725 while ($product_query->have_posts()) : $product_query->the_post();
726 $product = $_pf->get_product(get_the_ID());
727 $html .= '<li class="wp-chatbot-product">';
728 $html .= '<a class="wp-chatbot-product-url" wp-chatbot-pid= "' . get_the_ID() . '" target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->get_title() ? $product->get_title() : get_the_ID()) . '">';
729 $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '
730 <div class="wp-chatbot-product-summary">
731 <div class="wp-chatbot-product-table">
732 <div class="wp-chatbot-product-table-cell">
733 <h3 class="wp-chatbot-product-title">' . $product->get_title() . '</h3>
734 <div class="price">' . $product->get_price_html() . '</div>';
735 $html .= ' </div>
736 </div>
737 </div></a>
738 </li>';
739 endwhile;
740 wp_reset_postdata();
741 $html .= '</ul>';
742 if ($total_product_num > $product_per_page) {
743 $html .= '<p style="text-align: center"><button type="button" id="wp-chatbot-loadmore" data-offset="' . $product_per_page . '" data-search-type="product" data-search-term="featured" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_load_more')))) . ' <span id="wp-chatbot-loadmore-loader"></span></button> </p>';
744 }
745 }
746 $html .= '</div>';
747 $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page);
748 wp_send_json($response);
749 }
750 //Product display controll
751 function wp_chatbot_product_controlling($product_id){
752 $display_product = true;
753 //Controlling Out of Stock product display from back end.
754 $_pf = new WC_Product_Factory();
755 $product = $_pf->get_product($product_id);
756 if ($product->manage_stock == 'yes' && $product->stock_quantity <= 0 && get_option('wp_chatbot_exclude_stock_out_product') == 1) {
757 $display_product = false;
758 }
759 return $display_product;
760 }
761 //Get Sale products
762 add_action('wp_ajax_qcld_wb_chatbot_sale_products', 'qcld_wb_chatbot_sale_products');
763 add_action('wp_ajax_nopriv_qcld_wb_chatbot_sale_products', 'qcld_wb_chatbot_sale_products');
764 function qcld_wb_chatbot_sale_products(){
765 $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10);
766 $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title');
767 $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC');
768 //get sale products query.
769 $argu_params = array(
770 'post_type' => 'product',
771 'post_status' => 'publish',
772 'posts_per_page' => $product_per_page,
773 'meta_query' => array(
774 'relation' => 'OR',
775 array( // Simple products type
776 'key' => '_sale_price',
777 'value' => 0,
778 'compare' => '>',
779 'type' => 'numeric'
780 ),
781 array( // Variable products type
782 'key' => '_min_variation_sale_price',
783 'value' => 0,
784 'compare' => '>',
785 'type' => 'numeric'
786 )
787 )
788 );
789 /******
790 *WP Query Operation to get products.*
791 *******/
792 $product_query = new WP_Query($argu_params);
793 $product_num = $product_query->post_count;
794 //Getting total product number by string.
795 $total_argu = array(
796 'post_type' => 'product',
797 'post_status' => 'publish',
798 'posts_per_page' => 100,
799 'meta_query' => array(
800 'relation' => 'OR',
801 array( // Simple products type
802 'key' => '_sale_price',
803 'value' => 0,
804 'compare' => '>',
805 'type' => 'numeric'
806 ),
807 array( // Variable products type
808 'key' => '_min_variation_sale_price',
809 'value' => 0,
810 'compare' => '>',
811 'type' => 'numeric'
812 )
813 )
814 );
815 $total_query = new WP_Query($total_argu);
816 $total_product_num = $total_query->post_count;
817 $html = '<div class="wp-chatbot-products-area">';
818 $_pf = new WC_Product_Factory();
819 //repeating the products
820 if ($product_num > 0) {
821 //$html .= '<p>sdf sdfdsf : '.$asdfdf.'</p>';
822 $html .= '<ul class="wp-chatbot-products">';
823 while ($product_query->have_posts()) : $product_query->the_post();
824 $product = $_pf->get_product(get_the_ID());
825 $html .= '<li class="wp-chatbot-product">';
826 $html .= '<a class="wp-chatbot-product-url" wp-chatbot-pid= "' . get_the_ID() . '" target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->get_title() ? $product->get_title() : get_the_ID()) . '">';
827 $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '
828 <div class="wp-chatbot-product-summary">
829 <div class="wp-chatbot-product-table">
830 <div class="wp-chatbot-product-table-cell">
831 <h3 class="wp-chatbot-product-title">' . $product->get_title() . '</h3>
832 <div class="price">' . $product->get_price_html() . '</div>';
833 $html .= ' </div>
834 </div>
835 </div></a>
836 </li>';
837 endwhile;
838 wp_reset_postdata();
839 $html .= '</ul>';
840 if ($total_product_num > $product_per_page) {
841 $html .= '<p style="text-align: center"><button type="button" id="wp-chatbot-loadmore" data-offset="' . $product_per_page . '" data-search-type="product" data-search-term="sale" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_load_more')))) . ' <span id="wp-chatbot-loadmore-loader"></span></button> </p>';
842 }
843 }
844 $html .= '</div>';
845 $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page);
846 wp_send_json($response);
847 }
848 //load more
849 add_action('wp_ajax_qcld_wb_chatbot_load_more', 'qcld_wb_chatbot_load_more');
850 add_action('wp_ajax_nopriv_qcld_wb_chatbot_load_more', 'qcld_wb_chatbot_load_more');
851 function qcld_wb_chatbot_load_more(){
852 $offset = stripslashes($_POST['offset']);
853 $search_type = stripslashes($_POST['search_type']);
854 $search_term = stripslashes($_POST['search_term']);
855 $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10);
856 $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title');
857 $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC');
858 $next_offset = intval($product_per_page + $offset);
859 if ($search_type == 'product' && $search_term != 'featured' && $search_term != 'sale' && get_option('qlcd_wp_chatbot_search_option') == 'advanced') {
860 //if have multiple ids then explode else have single need to array push
861 if (strpos($search_term, ',') !== false) {
862 $product_ids = explode(',', $search_term);
863 } else {
864 $product_ids = array($search_term);
865 }
866 $result = wpwBot_Search::factory()->get_load_more_products($product_ids);
867 $products = $result['products'];
868 $product_num = count($result['products']);
869 $total_product_num = $result['total_products'];
870 $more_product_ids = implode(",", $result['more_ids']);
871 $_pf = new WC_Product_Factory();
872 //repeating the products
873 $html = '';
874 if ($product_num > 0) {
875 foreach ($products as $product) {
876 $html .= '<li class="wp-chatbot-product">';
877 $html .= '<a target="_blank" href="' . get_permalink($product->get_id()) . '" wp-chatbot-pid= "' . $product->get_id() . '" title="' . esc_attr($product->get_title()) . '">';
878 $html .= get_the_post_thumbnail($product->get_id(), 'shop_catalog') . '
879 <div class="wp-chatbot-product-summary">
880 <div class="wp-chatbot-product-table">
881 <div class="wp-chatbot-product-table-cell">
882 <h3 class="wp-chatbot-product-title">' . $product->get_title() . '</h3>
883 <div class="price">' . $product->get_price_html() . '</div>';
884 $html .= ' </div></div></div></a></li>';
885 }
886 }
887 $response = array('html' => $html, 'product_num' => $total_product_num, 'search_term' => $more_product_ids, 'offset' => $next_offset, 'per_page' => $product_per_page);
888 } else {
889 if ($search_type == 'product' && $search_term != 'featured' && $search_term != 'sale') { //For Standard search
890 $argu_params = array(
891 'post_type' => 'product',
892 'post_status' => 'publish',
893 'posts_per_page' => $product_per_page,
894 'offset' => $offset,
895 'orderby' => $product_orderby,
896 'order' => $product_order,
897 's' => $search_term,
898 );
899 } else if ($search_type == 'category') {
900 $argu_params = array(
901 'post_type' => 'product',
902 'post_status' => 'publish',
903 'ignore_sticky_posts' => 1,
904 'posts_per_page' => $product_per_page,
905 'orderby' => $product_orderby,
906 'order' => $product_order,
907 'offset' => $offset,
908 'tax_query' => array(
909 array(
910 'taxonomy' => 'product_cat',
911 'field' => 'term_id',
912 'terms' => $search_term,
913 'operator' => 'IN'
914 )
915 )
916 );
917 } else if ($search_type == 'product' && $search_term == 'featured') {
918 $argu_params = array(
919 'post_type' => 'product',
920 'post_status' => 'publish',
921 'ignore_sticky_posts' => 1,
922 'posts_per_page' => $product_per_page,
923 'orderby' => $product_orderby,
924 'order' => $product_order,
925 'offset' => $offset,
926 'meta_query' => array('key' => '_featured', 'value' => 'yes')
927 );
928 } else if ($search_type == 'product' && $search_term == 'sale') {
929 $argu_params = array(
930 'post_type' => 'product',
931 'post_status' => 'publish',
932 'ignore_sticky_posts' => 1,
933 'posts_per_page' => $product_per_page,
934 'orderby' => $product_orderby,
935 'order' => $product_order,
936 'offset' => $offset,
937 'meta_query' => array(
938 'relation' => 'OR',
939 array( // Simple products type
940 'key' => '_sale_price',
941 'value' => 0,
942 'compare' => '>',
943 'type' => 'numeric'
944 ),
945 array( // Variable products type
946 'key' => '_min_variation_sale_price',
947 'value' => 0,
948 'compare' => '>',
949 'type' => 'numeric'
950 )
951 )
952 );
953 }
954 $product_query = new WP_Query($argu_params);
955 $product_num = $product_query->post_count;
956 $_pf = new WC_Product_Factory();
957 //repeating the products
958 $html = '';
959 if ($product_num > 0) {
960 while ($product_query->have_posts()) : $product_query->the_post();
961 $product = $_pf->get_product(get_the_ID());
962 $html .= '<li class="wp-chatbot-product">';
963 $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" wp-chatbot-pid= "' . get_the_ID() . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '">';
964 $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '
965 <div class="wp-chatbot-product-summary">
966 <div class="wp-chatbot-product-table">
967 <div class="wp-chatbot-product-table-cell">
968 <h3 class="wp-chatbot-product-title">' . $product->post->post_title . '</h3>
969 <div class="price">' . $product->get_price_html() . '</div>';
970 $html .= ' </div>
971 </div>
972 </div></a>
973 </li>';
974 endwhile;
975 wp_reset_postdata();
976 } else {
977 $html .= '';
978 }
979 $response = array('html' => $html, 'product_num' => $product_num, 'search_term' => $search_term, 'offset' => $next_offset, 'per_page' => $product_per_page);
980 }
981 wp_send_json($response);
982 }
983 //product details
984 add_action('wp_ajax_qcld_wb_chatbot_product_details', 'qcld_wb_chatbot_product_details');
985 add_action('wp_ajax_nopriv_qcld_wb_chatbot_product_details', 'qcld_wb_chatbot_product_details');
986 function qcld_wb_chatbot_product_details(){
987 $product_id = stripslashes($_POST['wp_chatbot_pid']);
988 //Tracking product view from chat board
989 wp_chatbot_view_track_product_by_id($product_id);
990 //wpcommerce product factory
991 $wc_pf = new WC_Product_Factory();
992 $product = $wc_pf->get_product($product_id);
993 $product_type = $wc_pf->get_product_type($product_id);
994 $product_title = '<h2 id="wp-chatbot-product-title" ><a target="_blank" href="' . get_permalink($product->get_id()) . '">' . $product->get_title() . '</a></h2>';
995 $product_desc = apply_filters('the_excerpt', $product->post->post_excerpt);//$product->post->post_excerpt;
996 $gallery_ids = $product->get_gallery_image_ids();
997 //images processing..
998 $product_feature_image_id = get_post_thumbnail_id($product_id);
999 $product_feature_image = wp_get_attachment_image_src($product_feature_image_id, 'full');
1000 $product_feature_thumb = wp_get_attachment_image_src($product_feature_image_id, 'shop_thumbnail');
1001 //$full_img_src = $product_feature_image[0];
1002 //$product_image = '<img style="width:500px;height:300px" src="' . $full_img_src . '" >';
1003 $product_image = '<div class="wp-chatbot-product-image-large">
1004 <a href="' . $product_feature_image[0] . '" id="wp-chatbot-product-image-large-path"><img id="wp-chatbot-product-image-large-src" src="' . $product_feature_image[0] . '" alt="Large Image" title="Zoom Image" /></a>
1005 </div>';
1006 $product_image .= '<div class="wp-chatbot-product-image-thumbs"><ul>
1007 <li class="wp-chatbot-product-active-image-thumbs"><a href="' . $product_feature_image[0] . '" class="wp-chatbot-product-image-thumbs-path"><img class="wp-chatbot-product-image-thumbs-src" src="' . $product_feature_thumb[0] . '" alt="Thumb Image" /></a></li>';
1008 if (!empty($gallery_ids)) {
1009 foreach ($gallery_ids as $gallery_id) {
1010 $gallery_image = wp_get_attachment_image_src($gallery_id, 'full');
1011 $gallery_thumb = wp_get_attachment_image_src($gallery_id, 'shop_thumbnail');
1012 $product_image .= '<li><a href="' . $gallery_image[0] . '" class="wp-chatbot-product-image-thumbs-path"><img class="wp-chatbot-product-image-thumbs-src" src="' . $gallery_thumb[0] . '" alt="Thumb Image" /></a></li>';
1013 }
1014 }
1015 $product_image .= '</ul></div>';
1016 $product_price = '<p class="wp-chatbot-product-price" id="wp-chatbot-product-price">' . $product->get_price_html() . '</p>';
1017 $product_sku = '<p class="wp-chatbot-product-sku"> ' . __('SKU', 'wpchatbot') . ' : ' . $product->get_sku() . '</p>';
1018 //if ( $product->is_in_stock() || $product->is_purchasable() )
1019 //Handle variable product start
1020 $variations = "";
1021 $add_cart_button = "";
1022 $product_quantity = "";
1023 if ($product->is_in_stock()) {
1024 if ($product_type == "variable") {
1025 //Getting product variation number based details
1026 $variations_data = array();
1027 foreach ($product->get_children() as $child_id) {
1028 $all_cfs = get_post_custom($child_id);
1029 array_push($variations_data, array('variation_id' => $child_id, 'variation_data' => $all_cfs));
1030 }
1031 $variations_data = json_encode($variations_data);
1032 $attributes = $product->get_attributes();
1033 //Handling Variant & Non Variant products
1034 $var_attrs = $product->get_variation_attributes();
1035 $varation_names = array();
1036 if (!empty($var_attrs)) {
1037 foreach ($var_attrs as $key => $value) {
1038 array_push($varation_names, $key);
1039 }
1040 }
1041 $debug = $varation_names;
1042 foreach ($attributes as $attribute) {
1043 /*if (empty($attribute['is_visible']) || ($attribute['is_taxonomy'] && !taxonomy_exists($attribute['name']))) {
1044 continue;
1045 }*/
1046 $title = wc_attribute_label($attribute['name']);
1047 $name = $attribute['name'];
1048 if ($attribute['is_taxonomy']) {
1049 $values = wc_get_product_terms($product->get_id(), $attribute['name'], array('fields' => 'slugs'));
1050 } else {
1051 $values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
1052 }
1053 natsort($values);
1054 if (!in_array($name, $varation_names)) {
1055 $variations .= '<p><label for="' . sanitize_title($name) . '">' . $title . '</label> ' . ucfirst(implode(",", $values)) . '</p>';
1056 } else {
1057 $variations .= '<div class="wp-chatbot-variable-' . sanitize_title($name) . '">';
1058 $variations .= '<label for="' . sanitize_title($name) . '">' . $title . '</label>';
1059 $variations .= '<select id="' . esc_attr(sanitize_title($name)) . '" name="attribute_' . sanitize_title($name) . '" data-attribute_name="attribute_' . sanitize_title($name) . '" class="each_attribute">';
1060 $variations .= '<option value="">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_choose_option')))) . '</option>';
1061 foreach ($values as $value) {
1062 if (isset($_REQUEST['attribute_' . sanitize_title($name)])) {
1063 $selected_value = $_REQUEST['attribute_' . sanitize_title($name)];
1064 } else {
1065 $selected_value = '';
1066 }
1067 $variations .= '<option value="' . esc_attr(strtolower($value)) . '"' . selected($selected_value, $value, false) . '>' . apply_filters('wpcommerce_variation_option_name', $value) . '</option>';
1068 }
1069 $variations .= '</select></div>';
1070 }
1071 }
1072 $add_cart_button .= '<input type="button" id="wp-chatbot-variation-add-to-cart" wp-chatbot-product-id="' . $product_id . '" value="' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_add_to_cart')))) . '" variation_id="" />';
1073 $add_cart_button .= "<input type='hidden' id='wp-chatbot-variation-data' data-product-variation='" . $variations_data . "' />";
1074 } else {
1075 $add_cart_button .= '<input type="button" id="wp-chatbot-add-cart-button" wp-chatbot-product-id="' . $product_id . '" value="' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_add_to_cart')))) . '" />';
1076 }
1077 //Handle variable product end.
1078 $product_quantity .= '<label for="">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_quantity')))) . '</label>
1079 <input type="number" id="vPQuantity" value="1" />';
1080 }
1081 //$response=$full_size_image;
1082 $response = array('title' => $product_title, 'description' => $product_desc, 'image' => $product_image, 'price' => $product_price, 'sku' => $product_sku, 'quantity' => $product_quantity, 'buttton' => $add_cart_button, 'variation' => $variations, 'type' => $product_type, 'debug' => $debug);
1083 wp_send_json($response);
1084 }
1085 //Add to cart for variable product.
1086 add_action('wp_ajax_variable_add_to_cart', 'qcld_wb_chatbot_variable_add_to_cart');
1087 add_action('wp_ajax_nopriv_variable_add_to_cart', 'qcld_wb_chatbot_variable_add_to_cart');
1088 function qcld_wb_chatbot_variable_add_to_cart(){
1089 $product_id = stripslashes($_POST['p_id']);
1090 $quantity = stripslashes($_POST['quantity']);
1091 $variations_id = stripslashes($_POST['variations_id']);
1092 $attrs = stripslashes($_POST['attributes']);
1093 //echo wp_send_json(array('p_id'=>$product_id,'qnty'=>$quantity,'id'=>$variations_id,'att'=>$attrs));
1094 $attributes = array();
1095 foreach ($attrs as $attr) {
1096 $single = explode("#", $attr);
1097 if (isset($single[0])) {
1098 $a_name = explode("_", $single[0]);
1099 }
1100 $attributes[$a_name[2]] = $single[1];
1101 }
1102 global $wpcommerce;
1103 $result = $wpcommerce->cart->add_to_cart($product_id, $quantity, $variations_id, $attributes, null);
1104 if ($result != false) {
1105 wp_send_json('variable');
1106 } else {
1107 wp_send_json('error');
1108 }
1109 }
1110 //Add to cart for simple product.
1111 add_action('wp_ajax_qcld_wb_chatbot_add_to_cart', 'qcld_wb_chatbot_add_to_cart');
1112 add_action('wp_ajax_nopriv_qcld_wb_chatbot_add_to_cart', 'qcld_wb_chatbot_add_to_cart');
1113 function qcld_wb_chatbot_add_to_cart(){
1114 $product_id = stripslashes($_POST['product_id']);
1115 $product_quantity = stripslashes($_POST['quantity']);
1116 global $wpcommerce;
1117 $result = $wpcommerce->cart->add_to_cart($product_id, $product_quantity);
1118 if ($result != false) {
1119 wp_send_json('simple');
1120 } else {
1121 wp_send_json('error');
1122 }
1123 }
1124 //Support part
1125 add_action('wp_ajax_qcld_wb_chatbot_support_email', 'qcld_wb_chatbot_support_email');
1126 add_action('wp_ajax_nopriv_qcld_wb_chatbot_support_email', 'qcld_wb_chatbot_support_email');
1127 function qcld_wb_chatbot_support_email(){
1128 $name = trim(sanitize_text_field($_POST['name']));
1129 $email = sanitize_email($_POST['email']);
1130 $message = sanitize_text_field($_POST['message']);
1131 $subject = sanitize_text_field(get_option('qlcd_wp_chatbot_email_sub') != '' ? get_option('qlcd_wp_chatbot_email_sub') : 'Support Email from wpWBot by Client');
1132 //Extract Domain
1133 $url = get_site_url();
1134 $url = parse_url($url);
1135 $domain = $url['host'];
1136 //$admin_email = "admin@" . $domain;
1137 $admin_email = sanitize_email(get_option('admin_email'));
1138 $toEmail = sanitize_email(get_option('qlcd_wp_chatbot_admin_email') != '' ? get_option('qlcd_wp_chatbot_admin_email') : $admin_email);
1139
1140
1141 if(get_option('qlcd_wp_chatbot_from_email') && get_option('qlcd_wp_chatbot_from_email')!=''){
1142 $fromEmail = get_option('qlcd_wp_chatbot_from_email');
1143 }else{
1144 $fromEmail = "wordpress@" . $domain;
1145 }
1146
1147 //Starting messaging and status.
1148 $response['status'] = 'fail';
1149 $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_email_fail')));
1150 if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
1151 $response['message'] = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_invalid_email'))));
1152 $response['status'] = 'fail';
1153 } else {
1154 //build email body
1155 $bodyContent = "";
1156 $bodyContent .= '<p><strong>' . __('Support Request Details', 'wpchatbot') . ':</strong></p><hr>';
1157 $bodyContent .= '<p>' . __('Name', 'wpchatbot') . ' : ' . $name . '</p>';
1158 $bodyContent .= '<p>' . __('Email', 'wpchatbot') . ' : ' . $email . '</p>';
1159 $bodyContent .= '<p>' . __('Subject', 'wpchatbot') . ' : ' . $subject . '</p>';
1160 $bodyContent .= '<p>' . __('Message', 'wpchatbot') . ' : ' . $message . '</p>';
1161 $bodyContent .= '<p>' . __('Mail Generated on', 'wpchatbot') . ': ' . current_time('F j, Y, g:i a') . '</p>';
1162 $to = $toEmail;
1163 $body = $bodyContent;
1164 $headers = array();
1165 $headers[] = 'Content-Type: text/html; charset=UTF-8';
1166 $headers[] = 'From: ' . $name . ' <' . $fromEmail . '>';
1167 $headers[] = 'Reply-To: ' . $name . ' <' . $email . '>';
1168 $result = wp_mail($to, $subject, $body, $headers);
1169 if ($result) {
1170 $response['status'] = 'success';
1171 $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_email_sent')));
1172 }
1173
1174 }
1175 echo json_encode($response);
1176 die();
1177 }
1178 //Support Phone
1179 add_action('wp_ajax_qcld_wb_chatbot_support_phone', 'qcld_wb_chatbot_support_phone');
1180 add_action('wp_ajax_nopriv_qcld_wb_chatbot_support_phone', 'qcld_wb_chatbot_support_phone');
1181 function qcld_wb_chatbot_support_phone(){
1182 $name = trim(sanitize_text_field($_POST['name']));
1183 $phone =sanitize_text_field($_POST['phone']);
1184 $subject = 'WPBot Support Mail Request for Call Back';
1185 //Extract Domain
1186 $url = get_site_url();
1187 $url = parse_url($url);
1188 $domain = $url['host'];
1189 //$admin_email = "admin@" . $domain;
1190 $admin_email = get_option('admin_email');
1191 $toEmail = sanitize_email(get_option('qlcd_wp_chatbot_admin_email') != '' ? get_option('qlcd_wp_chatbot_admin_email') : $admin_email);
1192
1193
1194 if(get_option('qlcd_wp_chatbot_from_email') && get_option('qlcd_wp_chatbot_from_email')!=''){
1195 $fromEmail = sanitize_email(get_option('qlcd_wp_chatbot_from_email'));
1196 }else{
1197 $fromEmail = "wordpress@" . $domain;
1198 }
1199 //Starting messaging and status.
1200 $response['status'] = 'fail';
1201 $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_phone_fail')));
1202 //build email body
1203 $bodyContent = "";
1204 $bodyContent .= '<p><strong>' . __('Support Request Details', 'wpchatbot') . ':</strong></p><hr>';
1205 $bodyContent .= '<p>' . __('Name', 'wpchatbot') . ' : ' . $name . '</p>';
1206 $bodyContent .= '<p>' . __('Phone', 'wpchatbot') . ' : ' . $phone . '</p>';
1207 $bodyContent .= '<p>' . __('Subject', 'wpchatbot') . ' : ' . $subject . '</p>';
1208 $bodyContent .= '<p>' . __('Message', 'wpchatbot') . ' : ' . __(' Call me at ', 'wpchatbot'). $phone . '</p>';
1209 $bodyContent .= '<p>' . __('Mail Generated on', 'wpchatbot') . ': ' . current_time('F j, Y, g:i a') . '</p>';
1210 $to = $toEmail;
1211 $body = $bodyContent;
1212 $headers = array();
1213 $headers[] = 'Content-Type: text/html; charset=UTF-8';
1214 $headers[] = 'From: ' . $name . ' <' . $fromEmail . '>';
1215 $headers[] = 'Reply-To: ' . $name . ' <' . $fromEmail . '>';
1216 $result = wp_mail($to, $subject, $body, $headers);
1217 if ($result) {
1218 $response['status'] = 'success';
1219 $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_phone_sent')));
1220 }
1221 echo json_encode($response);
1222 die();
1223 }
1224 // Order Status part. removed
1225
1226 function wpb_randmom_message_handle($items){
1227 return $items[rand(0, count($items) - 1)];
1228 }
1229 function qcld_wb_chatbot_func_str_replace($messages = array()){
1230 $refined_mesgses = array();
1231 foreach ($messages as $message) {
1232 $refined_msg = str_replace('\\', '', $message);
1233 array_push($refined_mesgses, $refined_msg);
1234 }
1235 return $refined_mesgses;
1236 }
1237 add_action('wp_ajax_qcld_wb_chatbot_login_user', 'qcld_wb_chatbot_login_user');
1238 add_action('wp_ajax_nopriv_qcld_wb_chatbot_login_user', 'qcld_wb_chatbot_login_user');
1239 function qcld_wb_chatbot_login_user(){
1240 // First check the nonce, if it fails the function will break
1241 check_ajax_referer('wpwbot-order-nonce', 'security');
1242 // Nonce is checked, get the POST data and sign user on
1243 $info = array();
1244 $info['user_login'] = trim(sanitize_text_field($_POST['user_name']));
1245 $info['user_password'] = trim(sanitize_text_field($_POST['user_pass']));
1246 $info['remember'] = true;
1247 $user_signon = wp_signon($info, false);
1248 $response = array();
1249 if (is_wp_error($user_signon)) {
1250 $response['status'] = "fail";
1251 $response['message'] = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_order_password_incorrect'))));
1252 } else {
1253 $response = get_order_by_username($info['user_login']);
1254 $response['status'] = "success";
1255 }
1256 wp_send_json($response);
1257 }
1258 add_action('wp_ajax_qcld_wb_chatbot_loged_in_user_orders', 'qcld_wb_chatbot_loged_in_user_orders');
1259 add_action('wp_ajax_nopriv_qcld_wb_chatbot_loged_in_user_orders', 'qcld_wb_chatbot_loged_in_user_orders');
1260 function qcld_wb_chatbot_loged_in_user_orders(){
1261 $current_user = wp_get_current_user();
1262 $user_name = $current_user->user_login;
1263 $response = get_order_by_username($user_name);
1264 wp_send_json($response);
1265 }
1266 function get_order_by_username($user_name){
1267 global $post;
1268 $response = array();
1269 $response['status'] .= "success";
1270 $user = get_user_by('login', $user_name);
1271 // The query arguments
1272 $customer_orders = get_posts(array(
1273 'numberposts' => -1,
1274 'meta_key' => '_customer_user',
1275 'meta_value' => $user->ID,
1276 'post_type' => wc_get_order_types(),
1277 'post_status' => array_keys(wc_get_order_statuses()),
1278 'posts_per_page' => 10,
1279 'orderby' => 'date',
1280 ));
1281 $response['order_num'] = count($customer_orders);
1282 $order_html = '';
1283 if ($response['order_num'] > 0) {
1284 $response['message'] .= wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_order_found'))));
1285 $order_html .= '<div class="wp-chatbot-orders-container">
1286 <div class="wp-chatbot-orders-header">
1287 <div class="order-id">' . __('ID', 'wpchatbot') . '</div>
1288 <div class="order-date">' . __('Date', 'wpchatbot') . ' </div>
1289 <div class="order-items">' . __('Items', 'wpchatbot') . '</div>
1290 <div class="order-status">' . __('Status', 'wpchatbot') . '</div>
1291 </div>';
1292 foreach ($customer_orders as $order) {
1293 //Formatting order summery
1294 if (isset($_COOKIE['from_app']) && $_COOKIE['from_app'] == 'yes') {
1295 $thanks_page_id = sanitize_text_field(get_option('wp_chatbot_app_order_thankyou'));
1296 $thanks_parmanlink = esc_url(get_permalink($thanks_page_id));
1297 $order_url = '<a href="' . $thanks_parmanlink . '?order_id=' . $order->ID . '" >' . $order->ID . '</a>';
1298 } else {
1299 $order_url = '<a href="' . get_url(get_permalink(get_option('wpcommerce_myaccount_page_id')) . '/view-order/' . $order->ID) . '" target="_blank" >' . $order->ID . '</a>';
1300 }
1301 $order_html .= '<div class="wp-chatbot-orders-single">
1302 <div class="order-id"> ' . $order_url . '</div>
1303 <div class="order-date"> <p>' . date("m/d/Y", strtotime($order->post_date)) . '</p> </div>
1304 <div class="order-items">';
1305 $singleOrder = new WC_Order($order->ID);
1306 $items = $singleOrder->get_items();
1307 foreach ($items as $item) {
1308 $order_html .= '<p>' . $item["name"] . ' X ' . $item["qty"] . '</p>';
1309 }
1310 $order_html .= '</div>
1311 <div class="order-status">' . strtoupper(end(explode("-", $order->post_status))) . '</div>
1312
1313 </div>';
1314 }
1315 $order_html .= '</div>';
1316 } else {
1317 $response['message'] .= get_option('qlcd_wp_chatbot_sorry') . '! <strong>' . $user_name . '</strong>';
1318 $order_html .= '<p>' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_order_not_found')))) . '</p>';
1319 }
1320 $response['html'] = $order_html;
1321 return $response;
1322 }
1323 //Recently viewed products
1324 //keeping id in cookies as
1325 function wp_chatbot_track_product_view(){
1326 if (!is_singular('product')) {
1327 return;
1328 }
1329 global $post;
1330 wp_chatbot_view_track_product_by_id($post->ID);
1331 }
1332 function wp_chatbot_view_track_product_by_id($post_id){
1333 if (empty($_COOKIE['wp_chatbot_wpcommerce_recently_viewed']))
1334 $viewed_products = array();
1335 else
1336 $viewed_products = (array)explode('|', $_COOKIE['wp_chatbot_wpcommerce_recently_viewed']);
1337 if (!in_array($post_id, $viewed_products)) {
1338 $viewed_products[] = $post_id;
1339 }
1340 if (sizeof($viewed_products) > 15) {
1341 array_shift($viewed_products);
1342 }
1343 // Store for session only
1344 if( function_exists( 'wc_setcookie' ) ){
1345 wc_setcookie('wp_chatbot_wpcommerce_recently_viewed', implode('|', $viewed_products));
1346 }
1347 }
1348 add_action('template_redirect', 'wp_chatbot_track_product_view', 20);
1349 //recent view product ajax
1350 add_action('wp_ajax_qcld_wb_chatbot_recently_viewed_products', 'qcld_wb_chatbot_recently_viewed_products');
1351 add_action('wp_ajax_nopriv_qcld_wb_chatbot_recently_viewed_products', 'qcld_wb_chatbot_recently_viewed_products');
1352 function qcld_wb_chatbot_recently_viewed_products(){
1353 // Get wpCommerce Global
1354 $_pf = new WC_Product_Factory();
1355 //show post per page.
1356 $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10);
1357 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome'))));
1358 // Get recently viewed product cookies data
1359 $viewed_products = !empty($_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) ? (array)explode('|', $_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) : array();
1360 $viewed_products = array_filter(array_map('absint', $viewed_products));
1361 //get featured products if has.
1362 $featured_products = new WP_Query(array('post_status' => 'publish', 'posts_per_page' => $product_per_page, 'post_type' => 'product', 'tax_query' => array(array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured'))));
1363 //Getting recently vieew products.
1364 if (!empty($viewed_products)) {
1365 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_viewed_product_welcome'))));
1366 $product_query = new WP_Query(array(
1367 'posts_per_page' => $product_per_page,
1368 'no_found_rows' => 1,
1369 'post_status' => 'publish',
1370 'post_type' => 'product',
1371 'post__in' => $viewed_products,
1372 ));
1373 //Getting featured products
1374 } else if ($featured_products->post_count > 0) {
1375 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_featured_product_welcome'))));
1376 $product_query = $featured_products;
1377 } else {
1378 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome'))));
1379 //Getting recent products
1380 $product_query = new WP_Query(array('post_status' => 'publish', 'posts_per_page' => $product_per_page, 'post_type' => 'product', 'orderby' => 'date', 'order' => 'DESC'));
1381 }
1382 if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") {
1383 $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path');
1384 } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") {
1385 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image');
1386 } else {
1387 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png';
1388 }
1389 $html = '<div class="wp-chatbot-agent-profile">
1390 <div class="wp-chatbot-widget-avatar"><img src="' . esc_url($wp_chatbot_custom_icon_path) . '" alt=""></div>
1391 <div class="wp-chatbot-widget-agent">' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '</div>
1392 <div class="wp-chatbot-bubble">' . $wp_chatbot_product_title . '</div>
1393 </div>';
1394 if ($product_query->post_count > 0) {
1395 $html .= '<div class="wp-chatbot-products-area">';
1396 $html .= '<ul class="wp-chatbot-products">';
1397 while ($product_query->have_posts()) : $product_query->the_post();
1398 $product = $_pf->get_product(get_the_ID());
1399 $html .= '<li class="wp-chatbot-product">';
1400 $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" wp-chatbot-pid= "' . get_the_ID() . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '">';
1401 $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '
1402 <div class="wp-chatbot-product-summary">
1403 <div class="wp-chatbot-product-table">
1404 <div class="wp-chatbot-product-table-cell">
1405 <h3 class="wp-chatbot-product-title">' . $product->post->post_title . '</h3>
1406 <div class="price">' . $product->get_price_html() . '</div>';
1407 $html .= ' </div>
1408 </div>
1409 </div></a>
1410 </li>';
1411 endwhile;
1412 wp_reset_query();
1413 wp_reset_postdata();
1414 $html .= '</ul></div>';
1415 } else {
1416 $html .= '<div class="wp-chatbot-products-area">';
1417 $html .= '<p style="text-align: center">You have no products !';
1418 $html .= '</div>';
1419 }
1420 wp_send_json($html);
1421 }
1422 //Recently viewed product shortcode
1423 add_shortcode('wpwbot_products', 'qcld_wb_chatbot_recently_viewed_shortcode');
1424 function qcld_wb_chatbot_recently_viewed_shortcode(){
1425 // Get wpCommerce Global
1426 $_pf = new WC_Product_Factory();
1427 $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10);
1428 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome'))));
1429 // Get recently viewed product cookies data
1430 $viewed_products = !empty($_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) ? (array)explode('|', $_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) : array();
1431 $viewed_products = array_filter(array_map('absint', $viewed_products));
1432 //get featured products if has.
1433 $featured_products = new WP_Query(array('post_status' => 'publish', 'posts_per_page' => $product_per_page, 'post_type' => 'product', 'tax_query' => array(array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured'))));
1434 //Getting recently vieew products.
1435 if (!empty($viewed_products)) {
1436 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_viewed_product_welcome'))));
1437 $product_query = new WP_Query(array(
1438 'posts_per_page' => $product_per_page,
1439 'no_found_rows' => 1,
1440 'post_status' => 'publish',
1441 'post_type' => 'product',
1442 'post__in' => $viewed_products,
1443 ));
1444 //implementing featured products
1445 } else if ($featured_products->post_count > 0) {
1446 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_featured_product_welcome'))));
1447 $product_query = $featured_products;
1448 } else {
1449 $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome'))));
1450 //Getting recent products
1451 $product_query = new WP_Query(array('post_status' => 'publish', 'posts_per_page' => $product_per_page, 'post_type' => 'product', 'orderby' => 'date', 'order' => 'DESC'));
1452 }
1453 if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") {
1454 $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path');
1455 } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") {
1456 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image');
1457 } else {
1458 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png';
1459 }
1460 $html = '<div class="wp-chatbot-agent-profile">
1461 <div class="wp-chatbot-widget-avatar"><img src="' . esc_url($wp_chatbot_custom_icon_path) . '" alt=""></div>
1462 <div class="wp-chatbot-widget-agent">' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '</div>
1463 <div class="wp-chatbot-bubble">' . esc_html($wp_chatbot_product_title) . '</div>
1464 </div>';
1465 if ($product_query->post_count > 0) {
1466 $html .= '<div class="wp-chatbot-products-area">';
1467 $html .= '<ul class="wp-chatbot-products">';
1468 while ($product_query->have_posts()) : $product_query->the_post();
1469 $product = $_pf->get_product(get_the_ID());
1470 $html .= '<li class="wp-chatbot-product">';
1471 $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" wp-chatbot-pid= "' . get_the_ID() . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '">';
1472 $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '
1473 <div class="wp-chatbot-product-summary">
1474 <div class="wp-chatbot-product-table">
1475 <div class="wp-chatbot-product-table-cell">
1476 <h3 class="wp-chatbot-product-title">' . $product->post->post_title . '</h3>
1477 <div class="price">' . $product->get_price_html() . '</div>';
1478 $html .= ' </div>
1479 </div>
1480 </div></a>
1481 </li>';
1482 endwhile;
1483 wp_reset_query();
1484 wp_reset_postdata();
1485 $html .= '</ul></div>';
1486 } else {
1487 $html .= '<div class="wp-chatbot-products-area">';
1488 $html .= '<p style="text-align: center">' . __('You have no products', 'wpchatbot') . ' !';
1489 $html .= '</div>';
1490 }
1491 return $html;
1492 }
1493 //Show cart for wp chatbot
1494 add_action('wp_ajax_qcld_wb_chatbot_show_cart', 'qcld_wb_chatbot_show_cart');
1495 add_action('wp_ajax_nopriv_qcld_wb_chatbot_show_cart', 'qcld_wb_chatbot_show_cart');
1496 function qcld_wb_chatbot_show_cart(){
1497 global $wpcommerce;
1498 // $cart_url = $wpcommerce->cart->get_cart_url();
1499 $cart_url = wc_get_cart_url();
1500 $checkout_url = wc_get_checkout_url();
1501 //$checkout_url = $wpcommerce->cart->get_checkout_url();
1502 $items = $wpcommerce->cart->get_cart();
1503 $itemCount = $wpcommerce->cart->cart_contents_count;
1504 $cart_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_shopping_cart'))));
1505 $no_cart_item_msg = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items'))));
1506 if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") {
1507 $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path');
1508 } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") {
1509 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image');
1510 } else {
1511 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png';
1512 }
1513 $html = '<div class="wp-chatbot-agent-profile">
1514 <div class="wp-chatbot-widget-avatar"><img src="' . esc_url($wp_chatbot_custom_icon_path) . '" alt=""></div>
1515 <div class="wp-chatbot-widget-agent">' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '</div>
1516 <div class="wp-chatbot-bubble">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_welcome')))) . '</div>
1517 </div>';
1518 if ($itemCount >= 1) {
1519 $html .= '<div class ="wp-chatbot-cart-container">';
1520 $html .= '<div class="wp-chatbot-cart-header"><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_title')))) . '</div><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_quantity')))) . '</div><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_price')))) . '</div><div class="qcld-wp-chatbot-cell"></div></div>';
1521 $html .= '<div class ="wp-chatbot-cart-body">';
1522 foreach ($items as $item => $values) {
1523 $cart_item= apply_filters('wpcommerce_cart_item_product', $values['data'], $values, $item);
1524 //product image
1525 $getProductDetail = wc_get_product($values['product_id']);
1526 $price = get_post_meta($values['product_id'], '_price', true);
1527 $html .= '<div class="wp-chatbot-cart-single">
1528 <div class="qcld-wp-chatbot-cell"> <h3 class="wp-chatbot-title">' . $cart_item->get_title() . '</h3></div>';
1529 $html .= '<div class="qcld-wp-chatbot-cell">';
1530 $html .= '<input class="qcld-wp-chatbot-cart-item-qnty" data-cart-item="' . $item . '" type="number" min="1" value="' . $values['quantity'] . '"></div>';
1531 $html .= '<div class="qcld-wp-chatbot-cell"><span class="wp-chatbot-cart-price">' . apply_filters('wpcommerce_cart_item_price', WC()->cart->get_product_price($cart_item), $values, $item) . '</span> </div>';
1532 $html .= '<div class="qcld-wp-chatbot-cell"><span data-cart-item="' . $item . '" class="wp-chatbot-remove-cart-item">X</span></div> </div>';
1533 }
1534 $html .= ' </div>';//End of cart body
1535 $html .= '<div class="wp-chatbot-cart-single">
1536 <div class="qcld-wp-chatbot-cell"></div>
1537 <div class="qcld-wp-chatbot-cell"><strong>Total</strong></div>
1538 <div class="qcld-wp-chatbot-cell"><strong>' . $wpcommerce->cart->get_cart_total() . '</strong></div>
1539 </div>';
1540 $html .= '<div class="wp-chatbot-cart-footer"><div class="qcld-wp-chatbot-cart-page"><a class="wp-chatbot-cart-link" href="' . $cart_url . '" target="_blank" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_link')))) . '</a></div><div class="qcld-wp-chatbot-checkout"><a class="wp-chatbot-checkout-link" href="' . $checkout_url . '" target="_blank" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_checkout_link')))) . '</a></div></div>';
1541 $html .= ' </div>';
1542 } else {
1543 $html .= '<div class="wp-chatbot-cart-container">';
1544 $html .= '<div><p style="text-align:center">' . $no_cart_item_msg . '</p></div>';
1545 $html .= '</div>';
1546 }
1547 $response = array('html' => $html, 'items' => $itemCount);
1548 wp_send_json($response);
1549 }
1550 //cart onley for wp chatbot
1551 add_action('wp_ajax_qcld_wb_chatbot_only_cart', 'qcld_wb_chatbot_only_cart');
1552 add_action('wp_ajax_nopriv_qcld_wb_chatbot_only_cart', 'qcld_wb_chatbot_only_cart');
1553 function qcld_wb_chatbot_only_cart(){
1554 global $wpcommerce;
1555 // $cart_url = $wpcommerce->cart->get_cart_url();
1556 $cart_url = wc_get_cart_url();
1557 $checkout_url = wc_get_checkout_url();
1558 //$checkout_url = $wpcommerce->cart->get_checkout_url();
1559 $items = $wpcommerce->cart->get_cart();
1560 $itemCount = $wpcommerce->cart->cart_contents_count;
1561 $no_cart_item_msg = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items'))));
1562
1563 $html = '';
1564 if ($itemCount >= 1) {
1565 $html .= '<div class ="wp-chatbot-cart-container">';
1566 $html .= '<div class="wp-chatbot-cart-header"><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_title')))) . '</div><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_quantity')))) . '</div><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_price')))) . '</div><div class="qcld-wp-chatbot-cell"></div></div>';
1567 $html .= '<div class ="wp-chatbot-cart-body">';
1568 foreach ($items as $item => $values) {
1569 $cart_item= apply_filters('wpcommerce_cart_item_product', $values['data'], $values, $item);
1570 //product image
1571 $getProductDetail = wc_get_product($values['product_id']);
1572 $price = get_post_meta($values['product_id'], '_price', true);
1573 $html .= '<div class="wp-chatbot-cart-single">
1574 <div class="qcld-wp-chatbot-cell"> <h3 class="wp-chatbot-title">' . $cart_item->get_title() . '</h3></div>';
1575 $html .= '<div class="qcld-wp-chatbot-cell">';
1576 $html .= '<input class="qcld-wp-chatbot-cart-item-qnty" data-cart-item="' . $item . '" type="number" min="1" value="' . $values['quantity'] . '"></div>';
1577 $html .= '<div class="qcld-wp-chatbot-cell"><span class="wp-chatbot-cart-price">' . apply_filters('wpcommerce_cart_item_price', WC()->cart->get_product_price($cart_item), $values, $item) . '</span> </div>';
1578 $html .= '<div class="qcld-wp-chatbot-cell"><span data-cart-item="' . $item . '" class="wp-chatbot-remove-cart-item">X</span></div> </div>';
1579 }
1580 $html .= ' </div>';//End of cart body
1581 $html .= '<div class="wp-chatbot-cart-single">
1582 <div class="qcld-wp-chatbot-cell"></div>
1583 <div class="qcld-wp-chatbot-cell"><strong>Total</strong></div>
1584 <div class="qcld-wp-chatbot-cell"><strong>' . $wpcommerce->cart->get_cart_total() . '</strong></div>
1585 </div>';
1586 $html .= '<div class="wp-chatbot-cart-footer"><div class="qcld-wp-chatbot-cart-page"><a class="wp-chatbot-cart-link" href="' . $cart_url . '" target="_blank" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_link')))) . '</a></div><div class="qcld-wp-chatbot-checkout"><a class="wp-chatbot-checkout-link" href="' . $checkout_url . '" target="_blank" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_checkout_link')))) . '</a></div></div>';
1587 $html .= ' </div>';
1588 } else {
1589 $html .= '<div class="wp-chatbot-cart-container">';
1590 $html .= '<div><p style="text-align:center">' . esc_html($no_cart_item_msg) . '</p></div>';
1591 $html .= '</div>';
1592 }
1593 $response = array('html' => $html, 'items' => $itemCount);
1594 wp_send_json($response);
1595 }
1596 //Cart show Shortcode
1597 add_shortcode('wpwbot_cart', 'qcld_wb_chatbot_cart_shortcode');
1598 function qcld_wb_chatbot_cart_shortcode(){
1599 global $wpcommerce;
1600 $items = $wpcommerce->cart->get_cart();
1601 $itemCount = $wpcommerce->cart->cart_contents_count;
1602 $cart_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_shopping_cart'))));
1603 $no_cart_item_msg = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items'))));
1604 if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") {
1605 $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path');
1606 } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") {
1607 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image');
1608 } else {
1609 $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png';
1610 }
1611 $html = '<div class="wp-chatbot-agent-profile">
1612 <div class="wp-chatbot-widget-avatar"><img src="' . esc_url($wp_chatbot_custom_icon_path) . '" alt=""></div>
1613 <div class="wp-chatbot-widget-agent">' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '</div>
1614 <div class="wp-chatbot-bubble">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_welcome')))) . '</div>
1615 </div>';
1616 if ($itemCount >= 1) {
1617 $html .= '<div class ="wp-chatbot-cart-container">';
1618 $html .= '<div class="wp-chatbot-cart-header"><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_title')))) . '</div><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_quantity')))) . '</div><div class="qcld-wp-chatbot-cell">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_price')))) . '</div> <div class="qcld-wp-chatbot-cell"></div> </div>';
1619 $html .= '<div class ="wp-chatbot-cart-body">';
1620 foreach ($items as $item => $values) {
1621 $cart_item = apply_filters('wpcommerce_cart_item_product', $values['data'], $values, $item);
1622 //product image
1623 $getProductDetail = wc_get_product($values['product_id']);
1624 $price = get_post_meta($values['product_id'], '_price', true);
1625 $html .= '<div class="wp-chatbot-cart-single">
1626 <div class="qcld-wp-chatbot-cell"> <h3 class="wp-chatbot-title">' . $cart_item->get_title() . '</h3></div>';
1627 $html .= '<div class="qcld-wp-chatbot-cell">';
1628 $html .= '<input class="qcld-wp-chatbot-cart-item-qnty" data-cart-item="' . $item . '" type="number" min="1" value="' . $values['quantity'] . '"></div>';
1629 $html .= '<div class="qcld-wp-chatbot-cell"><span class="wp-chatbot-cart-price">' . apply_filters('wpcommerce_cart_item_price', WC()->cart->get_product_price($cart_item), $values, $item) . '</span> </div>';
1630 $html .= '<div class="qcld-wp-chatbot-cell"><span data-cart-item="' . $item . '" class="wp-chatbot-remove-cart-item">X</span></div> </div>';
1631 }
1632 $html .= ' </div>';//End of cart body
1633 $html .= '<div class="wp-chatbot-cart-single">
1634 <div class="qcld-wp-chatbot-cell"></div>
1635 <div class="qcld-wp-chatbot-cell"><strong>Total</strong></div>
1636 <div class="qcld-wp-chatbot-cell"><strong>' . $wpcommerce->cart->get_cart_total() . '</strong></div>
1637 </div>';
1638 $html .= '<div class="wp-chatbot-cart-footer"><div class="qcld-wp-chatbot-cart-page"><a href="' . site_url() . '/cart" target="_blank" >' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_link')))) . '</a></div><div class="qcld-wp-chatbot-checkout"><a href="' . site_url() . '/checkout" target="_blank">' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_checkout_link')))) . '</a></div></div>';
1639 $html .= ' </div>';
1640 } else {
1641 $html .= '<div class="wp-chatbot-cart-container">';
1642 $html .= '<div><p style="text-align:center">' . $no_cart_item_msg . '</p></div>';
1643 $html .= '</div>';
1644 }
1645 // $response=array('html'=>$html,'items'=>$itemCount);
1646 return $html;
1647 }
1648 //Updating the cart items.
1649 add_action('wp_ajax_qcld_wb_chatbot_update_cart_item_number', 'qcld_wb_chatbot_update_cart_item_number');
1650 add_action('wp_ajax_nopriv_qcld_wb_chatbot_update_cart_item_number', 'qcld_wb_chatbot_update_cart_item_number');
1651 function qcld_wb_chatbot_update_cart_item_number(){
1652 //getting cart items n
1653 $cart_item_key = sanitize_text_field($_POST['cart_item_key']);
1654 $qnty = sanitize_text_field($_POST['qnty']);
1655 global $wpcommerce;
1656 $result = $wpcommerce->cart->set_quantity($cart_item_key, $qnty);
1657 wp_send_json($result);
1658 }
1659 //Show item after removing from cart page.
1660 add_action('wp_ajax_qcld_wb_chatbot_cart_item_remove', 'qcld_wb_chatbot_cart_item_remove');
1661 add_action('wp_ajax_nopriv_qcld_wb_chatbot_cart_item_remove', 'qcld_wb_chatbot_cart_item_remove');
1662 function qcld_wb_chatbot_cart_item_remove(){
1663 //getting cart items n
1664 $cart_item_key = sanitize_text_field($_POST['cart_item']);
1665 global $wpcommerce;
1666 $result = $wpcommerce->cart->remove_cart_item($cart_item_key);
1667 wp_send_json($result);
1668 }
1669 //Show cart page by shortcode.
1670 add_action('wp_ajax_qcld_wb_chatbot_cart_page', 'qcld_wb_chatbot_cart_page');
1671 add_action('wp_ajax_nopriv_qcld_wb_chatbot_cart_page', 'qcld_wb_chatbot_cart_page');
1672 function qcld_wb_chatbot_cart_page(){
1673 global $wpcommerce;
1674 $itemCount = $wpcommerce->cart->cart_contents_count;
1675 $html = "";
1676 if ($itemCount < 0) {
1677 $html .= wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items'))));
1678 } else {
1679 $html .= do_shortcode("[wpcommerce_cart]");
1680 }
1681 wp_send_json($html);
1682 }
1683 //Show checkout page by shortcode.
1684 add_action('wp_ajax_qcld_wb_chatbot_checkout_page', 'qcld_wb_chatbot_checkout_page');
1685 add_action('wp_ajax_nopriv_qcld_wb_chatbot_checkout_page', 'qcld_wb_chatbot_checkout_page');
1686 function qcld_wb_chatbot_checkout_page(){
1687 global $wpcommerce;
1688 $itemCount = $wpcommerce->cart->cart_contents_count;
1689 $html = "";
1690 if ($itemCount < 0) {
1691 $status = 'no';
1692 $html .= wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items'))));
1693 } else {
1694 $status = 'yes';
1695 $checkout_page_id = get_option('wp_chatbot_app_checkout');
1696 $checkout_parmanlink = esc_url(get_permalink($checkout_page_id));
1697 $html .= $checkout_parmanlink;
1698 }
1699 $response = array('status' => $status, 'html' => $html);
1700 wp_send_json($response);
1701 }
1702 //_dynamic_intent
1703 function qc_dynamic_intent(){
1704 global $wpdb;
1705 $intents = array();
1706
1707 $ai_df = get_option('enable_wp_chatbot_dailogflow');
1708 $custom_intent_labels = maybe_unserialize( get_option('qlcd_wp_custon_intent_label'));
1709 if($ai_df==1 && isset($custom_intent_labels[0]) && trim($custom_intent_labels[0])!=''):
1710
1711 foreach($custom_intent_labels as $custom_intent_label):
1712 $intents[] = $custom_intent_label;
1713 endforeach;
1714
1715 endif;
1716
1717
1718
1719 if(class_exists('Qcformbuilder_Forms_Admin')){
1720
1721
1722 $results = $wpdb->get_results("SELECT * FROM ". $wpdb->prefix."wfb_forms where 1 and type='primary'");
1723 if(!empty($results)){
1724
1725 foreach($results as $result){
1726 $form = maybe_unserialize($result->config);
1727 $intents[] = $form['name'];
1728 }
1729
1730 }
1731 }
1732
1733 if(!empty($intents)){
1734 return implode(", ", $intents);
1735 }else{
1736 return '';
1737 }
1738
1739 }
1740
1741 //User login on Checkout page.
1742 // add_action('wp_ajax_qcld_wb_chatbot_checkout_user_login', 'qcld_wb_chatbot_checkout_user_login');
1743 // add_action('wp_ajax_nopriv_qcld_wb_chatbot_checkout_user_login', 'qcld_wb_chatbot_checkout_user_login');
1744 // function qcld_wb_chatbot_checkout_user_login(){
1745 // // Nonce is checked, get the POST data and sign user on
1746 // $info = array();
1747 // //$info['nonce'] = $_POST['nonce_val'];
1748 // $info['user_login'] = trim(sanitize_text_field($_POST['user_name']));
1749 // $info['user_password'] = trim(sanitize_text_field($_POST['user_pass']));
1750 // $info['remember'] = true;
1751 // $user_signon = wp_signon($info, false);
1752 // // $response=$info;
1753 // $response = array();
1754 // if (is_wp_error($user_signon)) {
1755 // // $response['status'] = "fail";
1756 // $response = "no";
1757 // } else {
1758 // $response = "yes";
1759 // }
1760 // wp_send_json($response);
1761 // }
1762 // Load template for App Order Thank You page url
1763 function wp_chatbot_load_app_template($template){
1764 if (is_page('wpwbot-mobile-app')) {
1765 return dirname(__FILE__) . '/templates/app-templates/app.php';
1766 }
1767 return $template;
1768 }
1769 add_filter('template_include', 'wp_chatbot_load_app_template', 99);
1770 // Load template for App Order Thank You page url
1771 function wp_chatbot_load_app_order_thankyou_template($template){
1772 if (is_page('wpwbot-app-order-thankyou')) {
1773 return dirname(__FILE__) . '/templates/app-templates/app-order-thankyou.php';
1774 }
1775 return $template;
1776 }
1777 add_filter('template_include', 'wp_chatbot_load_app_order_thankyou_template', 99);
1778 // Load template for App checkout
1779 function wp_chatbot_load_app_checkout_template($template){
1780 if (is_page('wpwbot-app-checkout')) {
1781 return dirname(__FILE__) . '/templates/app-templates/app-checkout.php';
1782 }
1783 return $template;
1784 }
1785 add_filter('template_include', 'wp_chatbot_load_app_checkout_template', 99);
1786 // Create embed page when plugin install or activate
1787 //register_activation_hook(__FILE__, 'wp_chatbot_create_app_order_thankyou_page');
1788 add_action('init', 'wp_chatbot_create_app_checkout_thankyou_page');
1789 function wp_chatbot_create_app_checkout_thankyou_page(){
1790 if (get_option('wp_chatbot_app_pages') == 1) {
1791 //Mobile App page create
1792 if (get_page_by_title('wpwBot Mobile App') == NULL) {
1793 //post status and options
1794 $app_page = array(
1795 'comment_status' => 'closed',
1796 'ping_status' => 'closed',
1797 'post_author' => get_current_user_id(),
1798 'post_date' => date('Y-m-d H:i:s'),
1799 'post_status' => 'publish',
1800 'post_title' => 'wpwBot Mobile App',
1801 'post_name' => 'wpwbot-mobile-app',
1802 'post_type' => 'page',
1803 );
1804 //insert page and save the id
1805 $wpwbot_app = wp_insert_post($app_page, false);
1806 //save the id in the database
1807 update_option('wp_chatbot_app_checkout', $wpwbot_app);
1808 }
1809 //App checkout page create
1810 if (get_page_by_title('wpwBot App Checkout') == NULL) {
1811 //post status and options
1812 $checkout_page = array(
1813 'comment_status' => 'closed',
1814 'ping_status' => 'closed',
1815 'post_author' => get_current_user_id(),
1816 'post_date' => date('Y-m-d H:i:s'),
1817 'post_status' => 'publish',
1818 'post_title' => 'wpwBot App Checkout',
1819 'post_name' => 'wpwbot-app-checkout',
1820 'post_type' => 'page',
1821 );
1822 //insert page and save the id
1823 $app_checkout = wp_insert_post($checkout_page, false);
1824 //save the id in the database
1825 update_option('wp_chatbot_app_checkout', $app_checkout);
1826 }
1827 //App Order thank you page create
1828 if (get_page_by_title('wpwBot App Order Thank You') == NULL) {
1829 //post status and options
1830 $thankyou_page = array(
1831 'comment_status' => 'closed',
1832 'ping_status' => 'closed',
1833 'post_author' => get_current_user_id(),
1834 'post_date' => date('Y-m-d H:i:s'),
1835 'post_status' => 'publish',
1836 'post_title' => 'wpwBot App Order Thank You',
1837 'post_name' => 'wpwbot-app-order-thankyou',
1838 'post_type' => 'page',
1839 );
1840 //insert page and save the id
1841 $app_order_thankyou = wp_insert_post($thankyou_page, false);
1842 //save the id in the database
1843 update_option('wp_chatbot_app_order_thankyou', $app_order_thankyou);
1844 }
1845 }
1846 //Keep tracking from App by cookies
1847 if (isset($_GET['from']) && $_GET['from'] == 'app') {
1848 if (!isset($_COOKIE['from_app'])) {
1849 setcookie('from_app', 'yes', (time() + 3600), '/');
1850 }
1851 }
1852 }
1853 /***
1854 * Override order Thank page for mobile app
1855 */
1856 add_action('wpcommerce_thankyou', 'qcld_wb_chatbot__redirect_after_purchase', 10, 1);
1857 function qcld_wb_chatbot__redirect_after_purchase($order_get_id){
1858 if (isset($_COOKIE['from_app']) && $_COOKIE['from_app'] == 'yes') {
1859 global $wp;
1860 if (is_checkout() && !empty($wp->query_vars['order-received'])) {
1861 $thanks_page_id = get_option('wp_chatbot_app_order_thankyou');
1862 $thanks_parmanlink = esc_url(get_permalink($thanks_page_id));
1863 wp_redirect($thanks_parmanlink . '?order_id=' . $order_get_id);
1864 exit;
1865 }
1866 } else {
1867 remove_action('wpcommerce_thankyou', 'qcld_wb_chatbot__redirect_after_purchase');
1868 do_action('wpcommerce_thankyou', $order_get_id);
1869 }
1870 }
1871
1872 function qcld_choose_random($array){
1873 return $array[array_rand($array)];
1874 }
1875
1876 //User session count
1877 add_action('wp_ajax_qcld_wb_chatbot_session_count', 'qcld_wb_chatbot_session_count');
1878 add_action('wp_ajax_nopriv_qcld_wb_chatbot_session_count', 'qcld_wb_chatbot_session_count');
1879 function qcld_wb_chatbot_session_count(){
1880 // Nonce is checked, get the POST data and sign user on
1881 global $wpdb;
1882 $wpdb->show_errors = true;
1883 $tableuser = $wpdb->prefix.'wpbot_sessions';
1884 $response = array();
1885
1886
1887 $session_exists = $wpdb->get_row("select * from $tableuser where 1 and id = '1'");
1888 if(empty($session_exists)){
1889 $wpdb->insert(
1890 $tableuser,
1891 array(
1892 'session' => 1,
1893 )
1894 );
1895 }else{
1896
1897 $session_id = $session_exists->id;
1898 $wpdb->update(
1899 $tableuser,
1900 array(
1901 'session'=>($session_exists->session+1),
1902 ),
1903 array('id'=>$session_id),
1904 array(
1905 '%d',
1906 ),
1907 array('%d')
1908 );
1909 }
1910
1911 wp_send_json($response);
1912 }
1913
1914 /* WPBot Chat History Addon check */
1915 function qcld_wpbot_is_active_chat_history(){
1916
1917 if(function_exists('qcwp_chat_session_menu_fnc') || function_exists( 'qcpdcs_chat_session_menu_fnc' ) ){
1918 return 1;
1919 }else{
1920 return 0;
1921 }
1922
1923 }
1924
1925 function qc_wpbot_input_validation( $data ) {
1926 $data = html_entity_decode($data);
1927 $data = trim($data);
1928 $data = stripslashes($data);
1929 $data = htmlspecialchars($data);
1930 return $data;
1931 }
1932 add_action('wp_ajax_small_talk_import', 'small_talk_import');
1933 function small_talk_import(){
1934 global $wpdb;
1935 $table = $wpdb->prefix.'wpbot_response';
1936 $csvFile = file(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . 'small_talk.csv');
1937 foreach ($csvFile as $line) {
1938 $line = str_getcsv($line, ',', '"');
1939 $wpdb->insert($table, array(
1940 'query' => $line[0],
1941 'keyword' => $line[1],
1942 'response' => $line[2],
1943 'category'=> $line[3],
1944 'intent'=> '',
1945 //'lang'=> 'en_US',
1946 ));
1947 }
1948 $table2 = $wpdb->prefix.'wpbot_response_category';
1949 $wpdb->insert($table2, array(
1950 'name' => 'smalltalk',
1951 ));
1952 update_option( 'qcld_small_talk_imported', 'yes' );
1953
1954 }
1955 function sanitize_array( &$array ) {
1956 if (!empty($array)) {
1957 foreach ($array as &$value) {
1958 if( !is_array($value) )
1959 // sanitize if value is not an array
1960 $value = sanitize_text_field( $value );
1961 else
1962 // go inside this function again
1963 $this->sanitize_array($value);
1964 }
1965 }
1966 return $array;
1967 }