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

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