PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 3.8.9
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v3.8.9
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 3.8.9, at functions.php

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