PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services / 5.7.5
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services v5.7.5
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.7.5, at functions.php

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