PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services / 4.0.6
WPBot – AI ChatBot for Live Support, Lead Generation, AI Services v4.0.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 8.5.2 8.5.0 8.4.9 All 531 releases
chatbot / functions.php

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

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