" . esc_html__('No wpWBot Theme Found!', 'wpchatbot') . ""; } ?>
' . esc_html(get_option('qlcd_wp_chatbot_host')) . ''; ?>
wpChatIcon
var wpbot_clear_cache = 1 '; delete_transient( 'bot_clear_cache' ); } }else{ ?> post_content, 'wpwbot')) { $wp_chatbot_load = false; } } $post_list = maybe_unserialize(get_option('wp_chatbot_exclude_post_list')); if( is_array( $post_list ) && in_array(get_post_type(), $post_list)){ $wp_chatbot_load = false; } if (wp_chatbot_is_mobile() && get_option('disable_wp_chatbot_on_mobile') == 1) { $wp_chatbot_load = false; } if (get_option('wp_chatbot_show_home_page') == 'off' && is_home()) { $wp_chatbot_load = false; } if (get_option('wp_chatbot_show_posts') == 'off' && 'post' == get_post_type()) { $wp_chatbot_load = false; } if(is_admin()){ $wp_chatbot_load = false; } return $wp_chatbot_load; } //checking Devices function wp_chatbot_is_mobile(){ $useragent = $_SERVER['HTTP_USER_AGENT']; 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))) { return true; } else { return false; } } //Checking wpwbot opening hour function wp_chatbot_check_opening_hours(){ $curent_day=strtolower(date('l',strtotime(current_time( 'mysql' )))); $current_time=date('H:i',strtotime(current_time( 'mysql'))); $is_wpwbot_open =false; if(get_option('wpwbot_hours')) { $wpwbot_times = wp_kses_post(unserialize(get_option('wpwbot_hours'))); if (isset($wpwbot_times[$curent_day])) { $day_times = $wpwbot_times[$curent_day]; if (!empty($day_times)) { foreach ($day_times as $day_time) { if(strtotime($current_time) > strtotime($day_time[0]) && strtotime($current_time) < strtotime($day_time[1]) ){ $is_wpwbot_open=true; } } } } } return $is_wpwbot_open; } //wpwBot shortcode. add_shortcode('wpwbot', 'wp_chatbot_short_code'); function wp_chatbot_short_code($atts = []){ ob_start(); wp_chatbot_shortcode_dom($atts); $content = ob_get_clean(); return $content; } function wp_chatbot_shortcode_dom($atts){ //Defaults & Set Parameters for shortcode extract(shortcode_atts( array( 'template' => '01', ), $atts )); ?>
" . esc_html__('No wpWBot Theme Found!', 'wpchatbot') . ""; } ?>
X
' . esc_html(get_option('qlcd_wp_chatbot_host')) . ''; ?>
wpChatIcon
" . esc_html__('No WPBot ShortCode Theme Found!', 'wpchatbot') . ""; } } //shortcode for wpWBot mobile app add_shortcode('wpwbot_app', 'wp_chatbot_mobile_app_short_code'); function wp_chatbot_mobile_app_short_code(){ ?>
" . esc_html__('No WPBot Theme Found!', 'wpchatbot') . ""; } ?>
'product', 'post_status' => 'publish', 'posts_per_page' => $product_per_page, 'orderby' => $product_orderby, 'order' => $product_order, 's' => $keyword, ); /****** *WP Query Operation to get products.* *******/ $product_query = new WP_Query($argu_params); $product_num = $product_query->post_count; //Getting total product number by string. $total_argu = array('post_type' => 'product', 's' => $keyword, 'posts_per_page' => 100); $total_query = new WP_Query($total_argu); $total_product_num = $total_query->post_count; $html = '
'; $_pf = new WC_Product_Factory(); //repeating the products if ($product_num > 0) { $html .= ''; if ($total_product_num > $product_per_page && $product_per_page > 0 ) { $html .= '

'; } } $html .= '
'; } else if (get_option('qlcd_wp_chatbot_search_option') == 'advanced') { $result = wpwBot_Search::factory()->search($keyword); $products = $result['products']; $product_num = count($result['products']); $total_product_num = $result['total_products']; $more_product_ids = implode(",", $result['more_ids']); $html = '
'; $_pf = new WC_Product_Factory(); //repeating the products if ($product_num > 0) { $html .= ''; if ($total_product_num > $product_per_page && $product_per_page > 0) { $html .= '

'; } } $html .= '
'; } $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page); wp_send_json($response); } /** * wpwBot Categories */ add_action('wp_ajax_qcld_wb_chatbot_category', 'qcld_wb_chatbot_category'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_category', 'qcld_wb_chatbot_category'); function qcld_wb_chatbot_category(){ $category_type="common"; if (get_option('wp_chatbot_show_parent_category') != "") { $terms = get_terms('product_cat', array('parent' => 0, 'hide_empty' => true, 'fields' => 'all')); } else { $terms = get_terms('product_cat', array('hide_empty' => true, 'fields' => 'all')); } $html = ""; foreach ($terms as $term) { $child_terms=get_terms('product_cat', array('parent' => $term->term_id, 'hide_empty' => true, 'fields' => 'all')); if(get_option('wp_chatbot_show_sub_category')==1 && count($child_terms) >0){ $category_type="hasChilds"; } $html .= '' . $term->name . ''; } wp_send_json($html); } /** * wpwBot Sub categories */ add_action('wp_ajax_qcld_wb_chatbot_sub_category', 'qcld_wb_chatbot_sub_category'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_sub_category', 'qcld_wb_chatbot_sub_category'); function qcld_wb_chatbot_sub_category(){ $parent_id = stripslashes($_POST['parent_id']); $terms = get_terms('product_cat', array('parent' => $parent_id, 'hide_empty' => true, 'fields' => 'all')); $html = ""; foreach ($terms as $term) { $html .= '' . $term->name . ''; } wp_send_json($html); } /** * wpwBot category product */ add_action('wp_ajax_qcld_wb_chatbot_category_products', 'qcld_wb_chatbot_category_products'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_category_products', 'qcld_wb_chatbot_category_products'); function qcld_wb_chatbot_category_products(){ $category_id = stripslashes($_POST['category']); $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10); $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title'); $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC'); //Merging all query together. $argu_params = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $product_orderby, 'order' => $product_order, 'posts_per_page' => $product_per_page, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $category_id, 'operator' => 'IN' ) ) ); /****** *WP Query Operation to get products.* *******/ $product_query = new WP_Query($argu_params); $product_num = $product_query->post_count; //Getting total product number by string. $total_argu = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 100, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $category_id, 'operator' => 'IN' ) ) ); $total_query = new WP_Query($total_argu); $total_product_num = $total_query->post_count; $_pf = new WC_Product_Factory(); //repeating the products $html = ''; if ($product_num > 0) { $html .= '
'; $html .= ''; if ($total_product_num > $product_per_page && $product_per_page >0) { $html .= '

'; } $html .= '
'; } else { $html = ''; } $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page); wp_send_json($response); } /** * wpwBot latest, featured, recent product */ add_action('wp_ajax_qcld_wb_chatbot_featured_products', 'qcld_wb_chatbot_featured_products'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_featured_products', 'qcld_wb_chatbot_featured_products'); function qcld_wb_chatbot_featured_products(){ $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10); $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title'); $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC'); //get featured products query. $argu_params = array('post_status' => 'publish', 'posts_per_page' => $product_per_page, 'post_type' => 'product', 'post_status' => 'publish', 'tax_query' => array(array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured')) ); /****** *WP Query Operation to get products.* *******/ $product_query = new WP_Query($argu_params); $product_num = $product_query->post_count; //Getting total product number by string. $total_argu = array('post_status' => 'publish', 'posts_per_page' => 100, 'post_type' => 'product', 'post_status' => 'publish', 'tax_query' => array(array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured',),) ); $total_query = new WP_Query($total_argu); $total_product_num = $total_query->post_count; $html = '
'; $_pf = new WC_Product_Factory(); //repeating the products if ($product_num > 0) { //$html .= '

sdf sdfdsf : '.$asdfdf.'

'; $html .= ''; if ($total_product_num > $product_per_page) { $html .= '

'; } } $html .= '
'; $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page); wp_send_json($response); } //Product display controll function wp_chatbot_product_controlling($product_id){ $display_product = true; //Controlling Out of Stock product display from back end. $_pf = new WC_Product_Factory(); $product = $_pf->get_product($product_id); if ($product->manage_stock == 'yes' && $product->stock_quantity <= 0 && get_option('wp_chatbot_exclude_stock_out_product') == 1) { $display_product = false; } return $display_product; } //Get Sale products add_action('wp_ajax_qcld_wb_chatbot_sale_products', 'qcld_wb_chatbot_sale_products'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_sale_products', 'qcld_wb_chatbot_sale_products'); function qcld_wb_chatbot_sale_products(){ $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10); $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title'); $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC'); //get sale products query. $argu_params = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $product_per_page, 'meta_query' => array( 'relation' => 'OR', array( // Simple products type 'key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ), array( // Variable products type 'key' => '_min_variation_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ) ) ); /****** *WP Query Operation to get products.* *******/ $product_query = new WP_Query($argu_params); $product_num = $product_query->post_count; //Getting total product number by string. $total_argu = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 100, 'meta_query' => array( 'relation' => 'OR', array( // Simple products type 'key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ), array( // Variable products type 'key' => '_min_variation_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ) ) ); $total_query = new WP_Query($total_argu); $total_product_num = $total_query->post_count; $html = '
'; $_pf = new WC_Product_Factory(); //repeating the products if ($product_num > 0) { //$html .= '

sdf sdfdsf : '.$asdfdf.'

'; $html .= ''; if ($total_product_num > $product_per_page) { $html .= '

'; } } $html .= '
'; $response = array('html' => $html, 'product_num' => $total_product_num, 'per_page' => $product_per_page); wp_send_json($response); } //load more add_action('wp_ajax_qcld_wb_chatbot_load_more', 'qcld_wb_chatbot_load_more'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_load_more', 'qcld_wb_chatbot_load_more'); function qcld_wb_chatbot_load_more(){ $offset = stripslashes($_POST['offset']); $search_type = stripslashes($_POST['search_type']); $search_term = stripslashes($_POST['search_term']); $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10); $product_orderby = sanitize_text_field(get_option('qlcd_wp_chatbot_product_orderby') != '' ? get_option('qlcd_wp_chatbot_product_orderby') : 'title'); $product_order = sanitize_text_field(get_option('qlcd_wp_chatbot_product_order') != '' ? get_option('qlcd_wp_chatbot_product_order') : 'ASC'); $next_offset = intval($product_per_page + $offset); if ($search_type == 'product' && $search_term != 'featured' && $search_term != 'sale' && get_option('qlcd_wp_chatbot_search_option') == 'advanced') { //if have multiple ids then explode else have single need to array push if (strpos($search_term, ',') !== false) { $product_ids = explode(',', $search_term); } else { $product_ids = array($search_term); } $result = wpwBot_Search::factory()->get_load_more_products($product_ids); $products = $result['products']; $product_num = count($result['products']); $total_product_num = $result['total_products']; $more_product_ids = implode(",", $result['more_ids']); $_pf = new WC_Product_Factory(); //repeating the products $html = ''; if ($product_num > 0) { foreach ($products as $product) { $html .= '
  • '; $html .= ''; $html .= get_the_post_thumbnail($product->get_id(), 'shop_catalog') . '

    ' . $product->get_title() . '

    ' . $product->get_price_html() . '
    '; $html .= '
  • '; } } $response = array('html' => $html, 'product_num' => $total_product_num, 'search_term' => $more_product_ids, 'offset' => $next_offset, 'per_page' => $product_per_page); } else { if ($search_type == 'product' && $search_term != 'featured' && $search_term != 'sale') { //For Standard search $argu_params = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $product_per_page, 'offset' => $offset, 'orderby' => $product_orderby, 'order' => $product_order, 's' => $search_term, ); } else if ($search_type == 'category') { $argu_params = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $product_per_page, 'orderby' => $product_orderby, 'order' => $product_order, 'offset' => $offset, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $search_term, 'operator' => 'IN' ) ) ); } else if ($search_type == 'product' && $search_term == 'featured') { $argu_params = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $product_per_page, 'orderby' => $product_orderby, 'order' => $product_order, 'offset' => $offset, 'meta_query' => array('key' => '_featured', 'value' => 'yes') ); } else if ($search_type == 'product' && $search_term == 'sale') { $argu_params = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $product_per_page, 'orderby' => $product_orderby, 'order' => $product_order, 'offset' => $offset, 'meta_query' => array( 'relation' => 'OR', array( // Simple products type 'key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ), array( // Variable products type 'key' => '_min_variation_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ) ) ); } $product_query = new WP_Query($argu_params); $product_num = $product_query->post_count; $_pf = new WC_Product_Factory(); //repeating the products $html = ''; if ($product_num > 0) { while ($product_query->have_posts()) : $product_query->the_post(); $product = $_pf->get_product(get_the_ID()); $html .= '
  • '; $html .= ''; $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '

    ' . $product->post->post_title . '

    ' . $product->get_price_html() . '
    '; $html .= '
  • '; endwhile; wp_reset_postdata(); } else { $html .= ''; } $response = array('html' => $html, 'product_num' => $product_num, 'search_term' => $search_term, 'offset' => $next_offset, 'per_page' => $product_per_page); } wp_send_json($response); } //product details add_action('wp_ajax_qcld_wb_chatbot_product_details', 'qcld_wb_chatbot_product_details'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_product_details', 'qcld_wb_chatbot_product_details'); function qcld_wb_chatbot_product_details(){ $product_id = stripslashes($_POST['wp_chatbot_pid']); //Tracking product view from chat board wp_chatbot_view_track_product_by_id($product_id); //wpcommerce product factory $wc_pf = new WC_Product_Factory(); $product = $wc_pf->get_product($product_id); $product_type = $wc_pf->get_product_type($product_id); $product_title = '

    ' . $product->get_title() . '

    '; $product_desc = apply_filters('the_excerpt', $product->post->post_excerpt);//$product->post->post_excerpt; $gallery_ids = $product->get_gallery_image_ids(); //images processing.. $product_feature_image_id = get_post_thumbnail_id($product_id); $product_feature_image = wp_get_attachment_image_src($product_feature_image_id, 'full'); $product_feature_thumb = wp_get_attachment_image_src($product_feature_image_id, 'shop_thumbnail'); //$full_img_src = $product_feature_image[0]; //$product_image = ''; $product_image = '
    Large Image
    '; $product_image .= '
    '; $product_price = '

    ' . $product->get_price_html() . '

    '; $product_sku = '

    ' . __('SKU', 'wpchatbot') . ' : ' . $product->get_sku() . '

    '; //if ( $product->is_in_stock() || $product->is_purchasable() ) //Handle variable product start $variations = ""; $add_cart_button = ""; $product_quantity = ""; if ($product->is_in_stock()) { if ($product_type == "variable") { //Getting product variation number based details $variations_data = array(); foreach ($product->get_children() as $child_id) { $all_cfs = get_post_custom($child_id); array_push($variations_data, array('variation_id' => $child_id, 'variation_data' => $all_cfs)); } $variations_data = json_encode($variations_data); $attributes = $product->get_attributes(); //Handling Variant & Non Variant products $var_attrs = $product->get_variation_attributes(); $varation_names = array(); if (!empty($var_attrs)) { foreach ($var_attrs as $key => $value) { array_push($varation_names, $key); } } $debug = $varation_names; foreach ($attributes as $attribute) { /*if (empty($attribute['is_visible']) || ($attribute['is_taxonomy'] && !taxonomy_exists($attribute['name']))) { continue; }*/ $title = wc_attribute_label($attribute['name']); $name = $attribute['name']; if ($attribute['is_taxonomy']) { $values = wc_get_product_terms($product->get_id(), $attribute['name'], array('fields' => 'slugs')); } else { $values = array_map('trim', explode(WC_DELIMITER, $attribute['value'])); } natsort($values); if (!in_array($name, $varation_names)) { $variations .= '

    ' . ucfirst(implode(",", $values)) . '

    '; } else { $variations .= '
    '; $variations .= ''; $variations .= '
    '; } } $add_cart_button .= ''; $add_cart_button .= ""; } else { $add_cart_button .= ''; } //Handle variable product end. $product_quantity .= ' '; } //$response=$full_size_image; $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); wp_send_json($response); } //Add to cart for variable product. add_action('wp_ajax_variable_add_to_cart', 'qcld_wb_chatbot_variable_add_to_cart'); add_action('wp_ajax_nopriv_variable_add_to_cart', 'qcld_wb_chatbot_variable_add_to_cart'); function qcld_wb_chatbot_variable_add_to_cart(){ $product_id = stripslashes($_POST['p_id']); $quantity = stripslashes($_POST['quantity']); $variations_id = stripslashes($_POST['variations_id']); $attrs = stripslashes($_POST['attributes']); //echo wp_send_json(array('p_id'=>$product_id,'qnty'=>$quantity,'id'=>$variations_id,'att'=>$attrs)); $attributes = array(); foreach ($attrs as $attr) { $single = explode("#", $attr); if (isset($single[0])) { $a_name = explode("_", $single[0]); } $attributes[$a_name[2]] = $single[1]; } global $wpcommerce; $result = $wpcommerce->cart->add_to_cart($product_id, $quantity, $variations_id, $attributes, null); if ($result != false) { wp_send_json('variable'); } else { wp_send_json('error'); } } //Add to cart for simple product. add_action('wp_ajax_qcld_wb_chatbot_add_to_cart', 'qcld_wb_chatbot_add_to_cart'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_add_to_cart', 'qcld_wb_chatbot_add_to_cart'); function qcld_wb_chatbot_add_to_cart(){ $product_id = stripslashes($_POST['product_id']); $product_quantity = stripslashes($_POST['quantity']); global $wpcommerce; $result = $wpcommerce->cart->add_to_cart($product_id, $product_quantity); if ($result != false) { wp_send_json('simple'); } else { wp_send_json('error'); } } //Support part add_action('wp_ajax_qcld_wb_chatbot_support_email', 'qcld_wb_chatbot_support_email'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_support_email', 'qcld_wb_chatbot_support_email'); function qcld_wb_chatbot_support_email(){ $name = trim(sanitize_text_field($_POST['name'])); $email = sanitize_email($_POST['email']); $message = sanitize_text_field($_POST['message']); $subject = sanitize_text_field(get_option('qlcd_wp_chatbot_email_sub') != '' ? get_option('qlcd_wp_chatbot_email_sub') : 'Support Email from wpWBot by Client'); //Extract Domain $url = get_site_url(); $url = parse_url($url); $domain = $url['host']; //$admin_email = "admin@" . $domain; $admin_email = sanitize_email(get_option('admin_email')); $toEmail = sanitize_email(get_option('qlcd_wp_chatbot_admin_email') != '' ? get_option('qlcd_wp_chatbot_admin_email') : $admin_email); if(get_option('qlcd_wp_chatbot_from_email') && get_option('qlcd_wp_chatbot_from_email')!=''){ $fromEmail = get_option('qlcd_wp_chatbot_from_email'); }else{ $fromEmail = "wordpress@" . $domain; } //Starting messaging and status. $response['status'] = 'fail'; $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_email_fail'))); if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { $response['message'] = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_invalid_email')))); $response['status'] = 'fail'; } else { //build email body $bodyContent = ""; $bodyContent .= '

    ' . __('Support Request Details', 'wpchatbot') . ':


    '; $bodyContent .= '

    ' . __('Name', 'wpchatbot') . ' : ' . $name . '

    '; $bodyContent .= '

    ' . __('Email', 'wpchatbot') . ' : ' . $email . '

    '; $bodyContent .= '

    ' . __('Subject', 'wpchatbot') . ' : ' . $subject . '

    '; $bodyContent .= '

    ' . __('Message', 'wpchatbot') . ' : ' . $message . '

    '; $bodyContent .= '

    ' . __('Mail Generated on', 'wpchatbot') . ': ' . current_time('F j, Y, g:i a') . '

    '; $to = $toEmail; $body = $bodyContent; $headers = array(); $headers[] = 'Content-Type: text/html; charset=UTF-8'; $headers[] = 'From: ' . $name . ' <' . $fromEmail . '>'; $headers[] = 'Reply-To: ' . $name . ' <' . $email . '>'; $result = wp_mail($to, $subject, $body, $headers); if ($result) { $response['status'] = 'success'; $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_email_sent'))); } } echo json_encode($response); die(); } //Support Phone add_action('wp_ajax_qcld_wb_chatbot_support_phone', 'qcld_wb_chatbot_support_phone'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_support_phone', 'qcld_wb_chatbot_support_phone'); function qcld_wb_chatbot_support_phone(){ $name = trim(sanitize_text_field($_POST['name'])); $phone =sanitize_text_field($_POST['phone']); $subject = 'WPBot Support Mail Request for Call Back'; //Extract Domain $url = get_site_url(); $url = parse_url($url); $domain = $url['host']; //$admin_email = "admin@" . $domain; $admin_email = get_option('admin_email'); $toEmail = sanitize_email(get_option('qlcd_wp_chatbot_admin_email') != '' ? get_option('qlcd_wp_chatbot_admin_email') : $admin_email); if(get_option('qlcd_wp_chatbot_from_email') && get_option('qlcd_wp_chatbot_from_email')!=''){ $fromEmail = sanitize_email(get_option('qlcd_wp_chatbot_from_email')); }else{ $fromEmail = "wordpress@" . $domain; } //Starting messaging and status. $response['status'] = 'fail'; $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_phone_fail'))); //build email body $bodyContent = ""; $bodyContent .= '

    ' . __('Support Request Details', 'wpchatbot') . ':


    '; $bodyContent .= '

    ' . __('Name', 'wpchatbot') . ' : ' . $name . '

    '; $bodyContent .= '

    ' . __('Phone', 'wpchatbot') . ' : ' . $phone . '

    '; $bodyContent .= '

    ' . __('Subject', 'wpchatbot') . ' : ' . $subject . '

    '; $bodyContent .= '

    ' . __('Message', 'wpchatbot') . ' : ' . __(' Call me at ', 'wpchatbot'). $phone . '

    '; $bodyContent .= '

    ' . __('Mail Generated on', 'wpchatbot') . ': ' . current_time('F j, Y, g:i a') . '

    '; $to = $toEmail; $body = $bodyContent; $headers = array(); $headers[] = 'Content-Type: text/html; charset=UTF-8'; $headers[] = 'From: ' . $name . ' <' . $fromEmail . '>'; $headers[] = 'Reply-To: ' . $name . ' <' . $fromEmail . '>'; $result = wp_mail($to, $subject, $body, $headers); if ($result) { $response['status'] = 'success'; $response['message'] = str_replace('\\', '',wp_kses_post(get_option('qlcd_wp_chatbot_phone_sent'))); } echo json_encode($response); die(); } // Order Status part. removed function wpb_randmom_message_handle($items){ return $items[rand(0, count($items) - 1)]; } function qcld_wb_chatbot_func_str_replace($messages = array()){ $refined_mesgses = array(); foreach ($messages as $message) { $refined_msg = str_replace('\\', '', $message); array_push($refined_mesgses, $refined_msg); } return $refined_mesgses; } add_action('wp_ajax_qcld_wb_chatbot_login_user', 'qcld_wb_chatbot_login_user'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_login_user', 'qcld_wb_chatbot_login_user'); function qcld_wb_chatbot_login_user(){ // First check the nonce, if it fails the function will break check_ajax_referer('wpwbot-order-nonce', 'security'); // Nonce is checked, get the POST data and sign user on $info = array(); $info['user_login'] = trim(sanitize_text_field($_POST['user_name'])); $info['user_password'] = trim(sanitize_text_field($_POST['user_pass'])); $info['remember'] = true; $user_signon = wp_signon($info, false); $response = array(); if (is_wp_error($user_signon)) { $response['status'] = "fail"; $response['message'] = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_order_password_incorrect')))); } else { $response = get_order_by_username($info['user_login']); $response['status'] = "success"; } wp_send_json($response); } add_action('wp_ajax_qcld_wb_chatbot_loged_in_user_orders', 'qcld_wb_chatbot_loged_in_user_orders'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_loged_in_user_orders', 'qcld_wb_chatbot_loged_in_user_orders'); function qcld_wb_chatbot_loged_in_user_orders(){ $current_user = wp_get_current_user(); $user_name = $current_user->user_login; $response = get_order_by_username($user_name); wp_send_json($response); } function get_order_by_username($user_name){ global $post; $response = array(); $response['status'] .= "success"; $user = get_user_by('login', $user_name); // The query arguments $customer_orders = get_posts(array( 'numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $user->ID, 'post_type' => wc_get_order_types(), 'post_status' => array_keys(wc_get_order_statuses()), 'posts_per_page' => 10, 'orderby' => 'date', )); $response['order_num'] = count($customer_orders); $order_html = ''; if ($response['order_num'] > 0) { $response['message'] .= wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_order_found')))); $order_html .= '
    ' . __('ID', 'wpchatbot') . '
    ' . __('Date', 'wpchatbot') . '
    ' . __('Items', 'wpchatbot') . '
    ' . __('Status', 'wpchatbot') . '
    '; foreach ($customer_orders as $order) { //Formatting order summery if (isset($_COOKIE['from_app']) && $_COOKIE['from_app'] == 'yes') { $thanks_page_id = sanitize_text_field(get_option('wp_chatbot_app_order_thankyou')); $thanks_parmanlink = esc_url(get_permalink($thanks_page_id)); $order_url = '' . $order->ID . ''; } else { $order_url = '' . $order->ID . ''; } $order_html .= '
    ' . $order_url . '

    ' . date("m/d/Y", strtotime($order->post_date)) . '

    '; $singleOrder = new WC_Order($order->ID); $items = $singleOrder->get_items(); foreach ($items as $item) { $order_html .= '

    ' . $item["name"] . ' X ' . $item["qty"] . '

    '; } $order_html .= '
    ' . strtoupper(end(explode("-", $order->post_status))) . '
    '; } $order_html .= '
    '; } else { $response['message'] .= get_option('qlcd_wp_chatbot_sorry') . '! ' . $user_name . ''; $order_html .= '

    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_order_not_found')))) . '

    '; } $response['html'] = $order_html; return $response; } //Recently viewed products //keeping id in cookies as function wp_chatbot_track_product_view(){ if (!is_singular('product')) { return; } global $post; wp_chatbot_view_track_product_by_id($post->ID); } function wp_chatbot_view_track_product_by_id($post_id){ if (empty($_COOKIE['wp_chatbot_wpcommerce_recently_viewed'])) $viewed_products = array(); else $viewed_products = (array)explode('|', $_COOKIE['wp_chatbot_wpcommerce_recently_viewed']); if (!in_array($post_id, $viewed_products)) { $viewed_products[] = $post_id; } if (sizeof($viewed_products) > 15) { array_shift($viewed_products); } // Store for session only if( function_exists( 'wc_setcookie' ) ){ wc_setcookie('wp_chatbot_wpcommerce_recently_viewed', implode('|', $viewed_products)); } } add_action('template_redirect', 'wp_chatbot_track_product_view', 20); //recent view product ajax add_action('wp_ajax_qcld_wb_chatbot_recently_viewed_products', 'qcld_wb_chatbot_recently_viewed_products'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_recently_viewed_products', 'qcld_wb_chatbot_recently_viewed_products'); function qcld_wb_chatbot_recently_viewed_products(){ // Get wpCommerce Global $_pf = new WC_Product_Factory(); //show post per page. $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10); $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome')))); // Get recently viewed product cookies data $viewed_products = !empty($_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) ? (array)explode('|', $_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) : array(); $viewed_products = array_filter(array_map('absint', $viewed_products)); //get featured products if has. $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')))); //Getting recently vieew products. if (!empty($viewed_products)) { $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_viewed_product_welcome')))); $product_query = new WP_Query(array( 'posts_per_page' => $product_per_page, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, )); //Getting featured products } else if ($featured_products->post_count > 0) { $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_featured_product_welcome')))); $product_query = $featured_products; } else { $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome')))); //Getting recent products $product_query = new WP_Query(array('post_status' => 'publish', 'posts_per_page' => $product_per_page, 'post_type' => 'product', 'orderby' => 'date', 'order' => 'DESC')); } if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") { $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path'); } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image'); } else { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png'; } $html = '
    ' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '
    ' . $wp_chatbot_product_title . '
    '; if ($product_query->post_count > 0) { $html .= '
    '; $html .= '
    '; } else { $html .= '
    '; $html .= '

    You have no products !'; $html .= '

    '; } wp_send_json($html); } //Recently viewed product shortcode add_shortcode('wpwbot_products', 'qcld_wb_chatbot_recently_viewed_shortcode'); function qcld_wb_chatbot_recently_viewed_shortcode(){ // Get wpCommerce Global $_pf = new WC_Product_Factory(); $product_per_page = sanitize_text_field(get_option('qlcd_wp_chatbot_ppp') != '' ? get_option('qlcd_wp_chatbot_ppp') : 10); $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome')))); // Get recently viewed product cookies data $viewed_products = !empty($_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) ? (array)explode('|', $_COOKIE['wp_chatbot_wpcommerce_recently_viewed']) : array(); $viewed_products = array_filter(array_map('absint', $viewed_products)); //get featured products if has. $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')))); //Getting recently vieew products. if (!empty($viewed_products)) { $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_viewed_product_welcome')))); $product_query = new WP_Query(array( 'posts_per_page' => $product_per_page, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, )); //implementing featured products } else if ($featured_products->post_count > 0) { $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_featured_product_welcome')))); $product_query = $featured_products; } else { $wp_chatbot_product_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_latest_product_welcome')))); //Getting recent products $product_query = new WP_Query(array('post_status' => 'publish', 'posts_per_page' => $product_per_page, 'post_type' => 'product', 'orderby' => 'date', 'order' => 'DESC')); } if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") { $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path'); } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image'); } else { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png'; } $html = '
    ' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '
    ' . esc_html($wp_chatbot_product_title) . '
    '; if ($product_query->post_count > 0) { $html .= '
    '; $html .= '
    '; } else { $html .= '
    '; $html .= '

    ' . __('You have no products', 'wpchatbot') . ' !'; $html .= '

    '; } return $html; } //Show cart for wp chatbot add_action('wp_ajax_qcld_wb_chatbot_show_cart', 'qcld_wb_chatbot_show_cart'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_show_cart', 'qcld_wb_chatbot_show_cart'); function qcld_wb_chatbot_show_cart(){ global $wpcommerce; // $cart_url = $wpcommerce->cart->get_cart_url(); $cart_url = wc_get_cart_url(); $checkout_url = wc_get_checkout_url(); //$checkout_url = $wpcommerce->cart->get_checkout_url(); $items = $wpcommerce->cart->get_cart(); $itemCount = $wpcommerce->cart->cart_contents_count; $cart_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_shopping_cart')))); $no_cart_item_msg = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items')))); if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") { $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path'); } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image'); } else { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png'; } $html = '
    ' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_welcome')))) . '
    '; if ($itemCount >= 1) { $html .= '
    '; $html .= '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_title')))) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_quantity')))) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_price')))) . '
    '; $html .= '
    '; foreach ($items as $item => $values) { $cart_item= apply_filters('wpcommerce_cart_item_product', $values['data'], $values, $item); //product image $getProductDetail = wc_get_product($values['product_id']); $price = get_post_meta($values['product_id'], '_price', true); $html .= '

    ' . $cart_item->get_title() . '

    '; $html .= '
    '; $html .= '
    '; $html .= '
    ' . apply_filters('wpcommerce_cart_item_price', WC()->cart->get_product_price($cart_item), $values, $item) . '
    '; $html .= '
    X
    '; } $html .= '
    ';//End of cart body $html .= '
    Total
    ' . $wpcommerce->cart->get_cart_total() . '
    '; $html .= ''; $html .= '
    '; } else { $html .= '
    '; $html .= '

    ' . $no_cart_item_msg . '

    '; $html .= '
    '; } $response = array('html' => $html, 'items' => $itemCount); wp_send_json($response); } //cart onley for wp chatbot add_action('wp_ajax_qcld_wb_chatbot_only_cart', 'qcld_wb_chatbot_only_cart'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_only_cart', 'qcld_wb_chatbot_only_cart'); function qcld_wb_chatbot_only_cart(){ global $wpcommerce; // $cart_url = $wpcommerce->cart->get_cart_url(); $cart_url = wc_get_cart_url(); $checkout_url = wc_get_checkout_url(); //$checkout_url = $wpcommerce->cart->get_checkout_url(); $items = $wpcommerce->cart->get_cart(); $itemCount = $wpcommerce->cart->cart_contents_count; $no_cart_item_msg = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items')))); $html = ''; if ($itemCount >= 1) { $html .= '
    '; $html .= '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_title')))) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_quantity')))) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_price')))) . '
    '; $html .= '
    '; foreach ($items as $item => $values) { $cart_item= apply_filters('wpcommerce_cart_item_product', $values['data'], $values, $item); //product image $getProductDetail = wc_get_product($values['product_id']); $price = get_post_meta($values['product_id'], '_price', true); $html .= '

    ' . $cart_item->get_title() . '

    '; $html .= '
    '; $html .= '
    '; $html .= '
    ' . apply_filters('wpcommerce_cart_item_price', WC()->cart->get_product_price($cart_item), $values, $item) . '
    '; $html .= '
    X
    '; } $html .= '
    ';//End of cart body $html .= '
    Total
    ' . $wpcommerce->cart->get_cart_total() . '
    '; $html .= ''; $html .= '
    '; } else { $html .= '
    '; $html .= '

    ' . esc_html($no_cart_item_msg) . '

    '; $html .= '
    '; } $response = array('html' => $html, 'items' => $itemCount); wp_send_json($response); } //Cart show Shortcode add_shortcode('wpwbot_cart', 'qcld_wb_chatbot_cart_shortcode'); function qcld_wb_chatbot_cart_shortcode(){ global $wpcommerce; $items = $wpcommerce->cart->get_cart(); $itemCount = $wpcommerce->cart->cart_contents_count; $cart_title = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_shopping_cart')))); $no_cart_item_msg = wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items')))); if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') == "custom-agent.png") { $wp_chatbot_custom_icon_path = get_option('wp_chatbot_custom_agent_path'); } else if (get_option('wp_chatbot_custom_agent_path') != "" && get_option('wp_chatbot_agent_image') != "custom-agent.png") { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . get_option('wp_chatbot_agent_image'); } else { $wp_chatbot_custom_icon_path = QCLD_wpCHATBOT_IMG_URL . 'custom-agent.png'; } $html = '
    ' . esc_html(get_option('qlcd_wp_chatbot_agent')) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_welcome')))) . '
    '; if ($itemCount >= 1) { $html .= '
    '; $html .= '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_title')))) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_quantity')))) . '
    ' . wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_cart_price')))) . '
    '; $html .= '
    '; foreach ($items as $item => $values) { $cart_item = apply_filters('wpcommerce_cart_item_product', $values['data'], $values, $item); //product image $getProductDetail = wc_get_product($values['product_id']); $price = get_post_meta($values['product_id'], '_price', true); $html .= '

    ' . $cart_item->get_title() . '

    '; $html .= '
    '; $html .= '
    '; $html .= '
    ' . apply_filters('wpcommerce_cart_item_price', WC()->cart->get_product_price($cart_item), $values, $item) . '
    '; $html .= '
    X
    '; } $html .= '
    ';//End of cart body $html .= '
    Total
    ' . $wpcommerce->cart->get_cart_total() . '
    '; $html .= ''; $html .= '
    '; } else { $html .= '
    '; $html .= '

    ' . $no_cart_item_msg . '

    '; $html .= '
    '; } // $response=array('html'=>$html,'items'=>$itemCount); return $html; } //Updating the cart items. add_action('wp_ajax_qcld_wb_chatbot_update_cart_item_number', 'qcld_wb_chatbot_update_cart_item_number'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_update_cart_item_number', 'qcld_wb_chatbot_update_cart_item_number'); function qcld_wb_chatbot_update_cart_item_number(){ //getting cart items n $cart_item_key = sanitize_text_field($_POST['cart_item_key']); $qnty = sanitize_text_field($_POST['qnty']); global $wpcommerce; $result = $wpcommerce->cart->set_quantity($cart_item_key, $qnty); wp_send_json($result); } //Show item after removing from cart page. add_action('wp_ajax_qcld_wb_chatbot_cart_item_remove', 'qcld_wb_chatbot_cart_item_remove'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_cart_item_remove', 'qcld_wb_chatbot_cart_item_remove'); function qcld_wb_chatbot_cart_item_remove(){ //getting cart items n $cart_item_key = sanitize_text_field($_POST['cart_item']); global $wpcommerce; $result = $wpcommerce->cart->remove_cart_item($cart_item_key); wp_send_json($result); } //Show cart page by shortcode. add_action('wp_ajax_qcld_wb_chatbot_cart_page', 'qcld_wb_chatbot_cart_page'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_cart_page', 'qcld_wb_chatbot_cart_page'); function qcld_wb_chatbot_cart_page(){ global $wpcommerce; $itemCount = $wpcommerce->cart->cart_contents_count; $html = ""; if ($itemCount < 0) { $html .= wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items')))); } else { $html .= do_shortcode("[wpcommerce_cart]"); } wp_send_json($html); } //Show checkout page by shortcode. add_action('wp_ajax_qcld_wb_chatbot_checkout_page', 'qcld_wb_chatbot_checkout_page'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_checkout_page', 'qcld_wb_chatbot_checkout_page'); function qcld_wb_chatbot_checkout_page(){ global $wpcommerce; $itemCount = $wpcommerce->cart->cart_contents_count; $html = ""; if ($itemCount < 0) { $status = 'no'; $html .= wp_kses_post(wpb_randmom_message_handle(unserialize(get_option('qlcd_wp_chatbot_no_cart_items')))); } else { $status = 'yes'; $checkout_page_id = get_option('wp_chatbot_app_checkout'); $checkout_parmanlink = esc_url(get_permalink($checkout_page_id)); $html .= $checkout_parmanlink; } $response = array('status' => $status, 'html' => $html); wp_send_json($response); } //_dynamic_intent function qc_dynamic_intent(){ global $wpdb; $intents = array(); $ai_df = get_option('enable_wp_chatbot_dailogflow'); $custom_intent_labels = maybe_unserialize( get_option('qlcd_wp_custon_intent_label')); if($ai_df==1 && isset($custom_intent_labels[0]) && trim($custom_intent_labels[0])!=''): foreach($custom_intent_labels as $custom_intent_label): $intents[] = $custom_intent_label; endforeach; endif; if(class_exists('Qcformbuilder_Forms_Admin')){ $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ". $wpdb->prefix."wfb_forms WHERE type= %s",'primary')); //DB Call OK, No Caching OK if(!empty($results)){ foreach($results as $result){ $form = maybe_unserialize($result->config); $intents[] = $form['name']; } } } if(!empty($intents)){ return implode(", ", $intents); }else{ return ''; } } //User login on Checkout page. // add_action('wp_ajax_qcld_wb_chatbot_checkout_user_login', 'qcld_wb_chatbot_checkout_user_login'); // add_action('wp_ajax_nopriv_qcld_wb_chatbot_checkout_user_login', 'qcld_wb_chatbot_checkout_user_login'); // function qcld_wb_chatbot_checkout_user_login(){ // // Nonce is checked, get the POST data and sign user on // $info = array(); // //$info['nonce'] = $_POST['nonce_val']; // $info['user_login'] = trim(sanitize_text_field($_POST['user_name'])); // $info['user_password'] = trim(sanitize_text_field($_POST['user_pass'])); // $info['remember'] = true; // $user_signon = wp_signon($info, false); // // $response=$info; // $response = array(); // if (is_wp_error($user_signon)) { // // $response['status'] = "fail"; // $response = "no"; // } else { // $response = "yes"; // } // wp_send_json($response); // } // Load template for App Order Thank You page url function wp_chatbot_load_app_template($template){ if (is_page('wpwbot-mobile-app')) { return dirname(__FILE__) . '/templates/app-templates/app.php'; } return $template; } add_filter('template_include', 'wp_chatbot_load_app_template', 99); // Load template for App Order Thank You page url function wp_chatbot_load_app_order_thankyou_template($template){ if (is_page('wpwbot-app-order-thankyou')) { return dirname(__FILE__) . '/templates/app-templates/app-order-thankyou.php'; } return $template; } add_filter('template_include', 'wp_chatbot_load_app_order_thankyou_template', 99); // Load template for App checkout function wp_chatbot_load_app_checkout_template($template){ if (is_page('wpwbot-app-checkout')) { return dirname(__FILE__) . '/templates/app-templates/app-checkout.php'; } return $template; } add_filter('template_include', 'wp_chatbot_load_app_checkout_template', 99); // Create embed page when plugin install or activate //register_activation_hook(__FILE__, 'wp_chatbot_create_app_order_thankyou_page'); add_action('init', 'wp_chatbot_create_app_checkout_thankyou_page'); function wp_chatbot_create_app_checkout_thankyou_page(){ if (get_option('wp_chatbot_app_pages') == 1) { //Mobile App page create if (get_page_by_title('wpwBot Mobile App') == NULL) { //post status and options $app_page = array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => get_current_user_id(), 'post_date' => date('Y-m-d H:i:s'), 'post_status' => 'publish', 'post_title' => 'wpwBot Mobile App', 'post_name' => 'wpwbot-mobile-app', 'post_type' => 'page', ); //insert page and save the id $wpwbot_app = wp_insert_post($app_page, false); //save the id in the database update_option('wp_chatbot_app_checkout', $wpwbot_app); } //App checkout page create if (get_page_by_title('wpwBot App Checkout') == NULL) { //post status and options $checkout_page = array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => get_current_user_id(), 'post_date' => date('Y-m-d H:i:s'), 'post_status' => 'publish', 'post_title' => 'wpwBot App Checkout', 'post_name' => 'wpwbot-app-checkout', 'post_type' => 'page', ); //insert page and save the id $app_checkout = wp_insert_post($checkout_page, false); //save the id in the database update_option('wp_chatbot_app_checkout', $app_checkout); } //App Order thank you page create if (get_page_by_title('wpwBot App Order Thank You') == NULL) { //post status and options $thankyou_page = array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => get_current_user_id(), 'post_date' => date('Y-m-d H:i:s'), 'post_status' => 'publish', 'post_title' => 'wpwBot App Order Thank You', 'post_name' => 'wpwbot-app-order-thankyou', 'post_type' => 'page', ); //insert page and save the id $app_order_thankyou = wp_insert_post($thankyou_page, false); //save the id in the database update_option('wp_chatbot_app_order_thankyou', $app_order_thankyou); } } //Keep tracking from App by cookies if (isset($_GET['from']) && $_GET['from'] == 'app') { if (!isset($_COOKIE['from_app'])) { setcookie('from_app', 'yes', (time() + 3600), '/'); } } } /*** * Override order Thank page for mobile app */ add_action('wpcommerce_thankyou', 'qcld_wb_chatbot__redirect_after_purchase', 10, 1); function qcld_wb_chatbot__redirect_after_purchase($order_get_id){ if (isset($_COOKIE['from_app']) && $_COOKIE['from_app'] == 'yes') { global $wp; if (is_checkout() && !empty($wp->query_vars['order-received'])) { $thanks_page_id = get_option('wp_chatbot_app_order_thankyou'); $thanks_parmanlink = esc_url(get_permalink($thanks_page_id)); wp_redirect($thanks_parmanlink . '?order_id=' . $order_get_id); exit; } } else { remove_action('wpcommerce_thankyou', 'qcld_wb_chatbot__redirect_after_purchase'); do_action('wpcommerce_thankyou', $order_get_id); } } function qcld_choose_random($array){ return $array[array_rand($array)]; } //User session count add_action('wp_ajax_qcld_wb_chatbot_session_count', 'qcld_wb_chatbot_session_count'); add_action('wp_ajax_nopriv_qcld_wb_chatbot_session_count', 'qcld_wb_chatbot_session_count'); function qcld_wb_chatbot_session_count(){ // Nonce is checked, get the POST data and sign user on global $wpdb; $wpdb->show_errors = true; $tableuser = $wpdb->prefix.'wpbot_sessions'; $response = array(); $session_exists = $wpdb->get_row($wpdb->prepare("select * from $tableuser where 1 and id = %d",1)); //DB Call OK, No Caching OK if(empty($session_exists)){ $wpdb->insert( $tableuser, array( 'session' => 1, ) ); //DB Call OK, No Caching OK }else{ $session_id = $session_exists->id; $wpdb->update( $tableuser, array( 'session'=>($session_exists->session+1), ), array('id'=>$session_id), array( '%d', ), array('%d') ); //DB Call OK, No Caching OK } wp_send_json($response); } /* WPBot Chat History Addon check */ function qcld_wpbot_is_active_chat_history(){ if(function_exists('qcwp_chat_session_menu_fnc') || function_exists( 'qcpdcs_chat_session_menu_fnc' ) ){ return 1; }else{ return 0; } } function qc_wpbot_input_validation( $data ) { $data = html_entity_decode($data); $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } add_action('wp_ajax_small_talk_import', 'small_talk_import'); function small_talk_import(){ global $wpdb; $table = $wpdb->prefix.'wpbot_response'; $csvFile = file(QCLD_wpCHATBOT_PLUGIN_DIR_PATH . 'small_talk.csv'); foreach ($csvFile as $line) { $line = str_getcsv($line, ',', '"'); $wpdb->insert($table, array( 'query' => $line[0], 'keyword' => $line[1], 'response' => $line[2], 'category'=> $line[3], 'intent'=> '', //'lang'=> 'en_US', )); //DB Call OK, No Caching OK } $table2 = $wpdb->prefix.'wpbot_response_category'; $wpdb->insert($table2, array( 'name' => 'smalltalk', )); //DB Call OK, No Caching OK update_option( 'qcld_small_talk_imported', 'yes' ); } function sanitize_array( &$array ) { if (!empty($array)) { foreach ($array as &$value) { if( !is_array($value) ) // sanitize if value is not an array $value = sanitize_text_field( $value ); else // go inside this function again $this->sanitize_array($value); } } return $array; }