PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 4.3.8
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v4.3.8
8.7.8 8.7.7 8.7.6 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 All 534 releases
chatbot / functions.php

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

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