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

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