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

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