woowbot-woocommerce-chatbot
Last commit date
css
5 years ago
fonts
5 years ago
images
5 years ago
js
5 years ago
lang
5 years ago
qc-support-promo-page
5 years ago
class-plugin-deactivate-feedback.php
5 years ago
class-qc-free-plugin-upgrade-notice.php
5 years ago
functions.php
5 years ago
qcld-woowbot-info-page.php
5 years ago
qcld-woowbot.php
5 years ago
readme.txt
5 years ago
woowbot-slick-button.png
5 years ago
functions.php
236 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @param $type |
| 5 | * Display recently viewed products |
| 6 | */ |
| 7 | if (!defined('ABSPATH')) exit; // Exit if accessed directly |
| 8 | |
| 9 | |
| 10 | add_action('wp_footer', 'woo_chatbot_load_footer_html'); |
| 11 | function woo_chatbot_load_footer_html() |
| 12 | { ?> |
| 13 | <?php if (get_option('disable_woo_chatbot') != 1 && woo_chatbot_load_controlling()==true): ?> |
| 14 | <style> |
| 15 | <?php if(get_option('woo_chatbot_custom_css')!=""){echo get_option('woo_chatbot_custom_css'); } ?> |
| 16 | <?php |
| 17 | |
| 18 | if (get_option('qcld_woo_chatbot_change_bg') == 1) { |
| 19 | if (get_option('qcld_woo_chatbot_board_bg_path') != ""){ |
| 20 | |
| 21 | $qcld_woo_chatbot_board_bg_path = get_option('qcld_woo_chatbot_board_bg_path'); |
| 22 | |
| 23 | ?> |
| 24 | |
| 25 | .woo-chatbot-ball-inner { |
| 26 | background-image: url(<?php echo $qcld_woo_chatbot_board_bg_path;?>) !important; |
| 27 | background-size: cover; |
| 28 | background-position: center center; |
| 29 | } |
| 30 | <?php |
| 31 | } |
| 32 | } |
| 33 | ?> |
| 34 | |
| 35 | </style> |
| 36 | <div id="woo-chatbot-icon-container"> |
| 37 | <div id="woo-chatbot-ball-wrapper" style="display:none"> |
| 38 | |
| 39 | <div id="woo-chatbot-ball-container" style="display:none" class="woo-chatbot-ball-container"> |
| 40 | <div class="woo-chatbot-admin"> |
| 41 | <h4><?php if(get_option('qlcd_woo_chatbot_conversations_with')!=''){echo get_option('qlcd_woo_chatbot_conversations_with');}else{ _e('Conversations with', 'woochatbot'); } ?></h4> |
| 42 | <h3> <?php if(get_option('qlcd_woo_chatbot_agent')!=''){echo get_option('qlcd_woo_chatbot_agent');} ?></h3> |
| 43 | </div> |
| 44 | <div class="woo-chatbot-ball-inner"> |
| 45 | <div class="woo-chatbot-messages-wrapper"> |
| 46 | <ul id="woo-chatbot-messages-container" class="woo-chatbot-messages-container"> |
| 47 | </ul> |
| 48 | </div> |
| 49 | </div> |
| 50 | <div id="woo-chatbot-editor-container" class="woo-chatbot-editor-container"> |
| 51 | <input id="woo-chatbot-editor" class="woo-chatbot-editor" required placeholder="<?php _e('Send a message.', 'woochatbot'); ?>" |
| 52 | maxlength="100"> |
| 53 | <button type="button" id="woo-chatbot-send-message" class="woo-chatbot-button"><?php _e('send', 'woochatbot'); ?></button> |
| 54 | </div> |
| 55 | </div> |
| 56 | <!--woo-chatbot-ball-container--> |
| 57 | <div id="woo-chatbot-ball" class="woo-chatbot-ball"> |
| 58 | <img src="<?php echo QCLD_WOOCHATBOT_IMG_URL . '/' . get_option('woo_chatbot_icon'); ?>" |
| 59 | alt="WooChatIcon"> |
| 60 | </div> |
| 61 | <!--container--> |
| 62 | </div> |
| 63 | <!--woo-chatbot-ball-wrapper--> |
| 64 | </div> |
| 65 | <?php endif; |
| 66 | |
| 67 | } |
| 68 | |
| 69 | add_action('wp_ajax_qcld_woo_chatbot_keyword', 'qcld_woo_chatbot_keyword'); |
| 70 | add_action('wp_ajax_nopriv_qcld_woo_chatbot_keyword', 'qcld_woo_chatbot_keyword'); |
| 71 | |
| 72 | |
| 73 | function qcld_woo_chatbot_keyword() |
| 74 | { |
| 75 | $keyword = sanitize_text_field($_POST['keyword']); |
| 76 | $product_per_page=get_option('qlcd_woo_chatbot_ppp')!=''? get_option('qlcd_woo_chatbot_ppp') :10; |
| 77 | //Merging all query together. |
| 78 | $argu_params = array( |
| 79 | 'post_type' => 'product', |
| 80 | 'post_status' => 'publish', |
| 81 | 'posts_per_page' => $product_per_page, |
| 82 | 'order' => 'ASC', |
| 83 | 's' => $keyword, |
| 84 | ); |
| 85 | /****** |
| 86 | *WP Query Operation to get products.* |
| 87 | *******/ |
| 88 | $product_query = new WP_Query($argu_params); |
| 89 | $product_num = $product_query->post_count; |
| 90 | $html = '<div class="woo-chatbot-featured-products">'; |
| 91 | |
| 92 | $_pf = new WC_Product_Factory(); |
| 93 | //repeating the products |
| 94 | if ($product_num > 0) { |
| 95 | //$html .= '<p>sdf sdfdsf : '.$asdfdf.'</p>'; |
| 96 | $html .= '<ul class="woo-chatbot-products">'; |
| 97 | while ($product_query->have_posts()) : $product_query->the_post(); |
| 98 | $product = $_pf->get_product(get_the_ID()); |
| 99 | //$qcld_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'shop_thumbnail' ); |
| 100 | $html .= '<li class="woo-chatbot-product">'; |
| 101 | $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->get_title()) . '">'; |
| 102 | $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '</a> |
| 103 | <div class="woo-chatbot-product-summary"> |
| 104 | <div class="woo-chatbot-product-table"> |
| 105 | <div class="woo-chatbot-product-table-cell"> |
| 106 | <h3 class="woo-chatbot-product-title"><a target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->get_title()) . '">' . esc_attr($product->get_title()) . '</a></h3> |
| 107 | <div class="price">' . $product->get_price_html() . '</div>'; |
| 108 | |
| 109 | // if ($product->is_type('simple')) { |
| 110 | // $html .= '<a target="_blank" href="' . get_site_url() . '?add-to-cart=' . get_the_ID() . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '" class="woo-chatbot-button woo-chatbot-button-cart add_to_cart_button ajax_add_to_cart" data-quantity="1" data-product_id="' . get_the_ID() . '" >Add to Cart</a>'; |
| 111 | // } else { |
| 112 | // $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '" class="woo-chatbot-button woo-chatbot-button-cart" >View Detail</a>'; |
| 113 | // } |
| 114 | $html .= ' </div> |
| 115 | </div> |
| 116 | </div> |
| 117 | </li>'; |
| 118 | endwhile; |
| 119 | wp_reset_postdata(); |
| 120 | $html .= '</ul>'; |
| 121 | } |
| 122 | $html .= '</div>'; |
| 123 | $response = array('html' => $html, 'product_num' => $product_num); |
| 124 | echo wp_send_json($response); |
| 125 | wp_die(); |
| 126 | } |
| 127 | |
| 128 | add_action('wp_ajax_qcld_woo_chatbot_category', 'qcld_woo_chatbot_category'); |
| 129 | add_action('wp_ajax_nopriv_qcld_woo_chatbot_category', 'qcld_woo_chatbot_category'); |
| 130 | |
| 131 | function qcld_woo_chatbot_category() |
| 132 | { |
| 133 | $terms = get_terms(array( |
| 134 | 'taxonomy' => 'product_cat', |
| 135 | 'hide_empty' => true, |
| 136 | )); |
| 137 | $html = ""; |
| 138 | foreach ($terms as $term) { |
| 139 | |
| 140 | $html .= '<span class="qcld-chatbot-product-category" type="button" data-category-slug="' . $term->slug . '" data-category-id="' . $term->term_id . '">' . $term->name . '</span>'; |
| 141 | } |
| 142 | echo wp_send_json($html); |
| 143 | wp_die(); |
| 144 | } |
| 145 | |
| 146 | add_action('wp_ajax_qcld_woo_chatbot_category_products', 'qcld_woo_chatbot_category_products'); |
| 147 | add_action('wp_ajax_nopriv_qcld_woo_chatbot_category_products', 'qcld_woo_chatbot_category_products'); |
| 148 | function qcld_woo_chatbot_category_products() |
| 149 | { |
| 150 | $category_id = stripslashes($_POST['category']); |
| 151 | $product_per_page=get_option('qlcd_woo_chatbot_ppp')!=''? get_option('qlcd_woo_chatbot_ppp') :10; |
| 152 | //Merging all query together. |
| 153 | $argu_params = array( |
| 154 | 'post_type' => 'product', |
| 155 | 'post_status' => 'publish', |
| 156 | 'ignore_sticky_posts' => 1, |
| 157 | 'posts_per_page' => $product_per_page, |
| 158 | 'tax_query' => array( |
| 159 | array( |
| 160 | 'taxonomy' => 'product_cat', |
| 161 | 'field' => 'term_id', |
| 162 | 'terms' => $category_id, |
| 163 | 'operator' => 'IN' |
| 164 | ) |
| 165 | ) |
| 166 | ); |
| 167 | /****** |
| 168 | *WP Query Operation to get products.* |
| 169 | *******/ |
| 170 | $product_query = new WP_Query($argu_params); |
| 171 | $product_num = $product_query->post_count; |
| 172 | |
| 173 | $_pf = new WC_Product_Factory(); |
| 174 | //repeating the products |
| 175 | $html=""; |
| 176 | if ($product_num > 0) { |
| 177 | |
| 178 | $html .= '<div class="woo-chatbot-featured-products">'; |
| 179 | //$html .= '<p>sdf sdfdsf : '.$asdfdf.'</p>'; |
| 180 | $html .= '<ul class="woo-chatbot-products">'; |
| 181 | while ($product_query->have_posts()) : $product_query->the_post(); |
| 182 | $product = $_pf->get_product(get_the_ID()); |
| 183 | //$qcld_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'shop_thumbnail' ); |
| 184 | $html .= '<li class="woo-chatbot-product">'; |
| 185 | $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '">'; |
| 186 | $html .= get_the_post_thumbnail(get_the_ID(), 'shop_catalog') . '</a> |
| 187 | <div class="woo-chatbot-product-summary"> |
| 188 | <div class="woo-chatbot-product-table"> |
| 189 | <div class="woo-chatbot-product-table-cell"> |
| 190 | <h3 class="woo-chatbot-product-title"><a target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '">' . $product->post->post_title . '</a></h3> |
| 191 | <div class="price">' . $product->get_price_html() . '</div>'; |
| 192 | |
| 193 | // if ($product->is_type('simple')) { |
| 194 | // $html .= '<a target="_blank" href="' . get_site_url() . '?add-to-cart=' . get_the_ID() . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '" class="woo-chatbot-button woo-chatbot-button-cart add_to_cart_button ajax_add_to_cart" data-quantity="1" data-product_id="' . get_the_ID() . '" >Add to Cart</a>'; |
| 195 | // } else { |
| 196 | // $html .= '<a target="_blank" href="' . get_permalink(get_the_ID()) . '" title="' . esc_attr($product->post->post_title ? $product->post->post_title : get_the_ID()) . '" class="woo-chatbot-button woo-chatbot-button-cart" >View Detail</a>'; |
| 197 | // } |
| 198 | $html .= ' </div> |
| 199 | </div> |
| 200 | </div> |
| 201 | </li>'; |
| 202 | endwhile; |
| 203 | wp_reset_postdata(); |
| 204 | $html .= '</ul>'; |
| 205 | |
| 206 | $html .= '</div>'; |
| 207 | }else{ |
| 208 | $html.=""; |
| 209 | } |
| 210 | $response = array('html' => $html, 'product_num' => $product_num); |
| 211 | echo wp_send_json($response); |
| 212 | wp_die(); |
| 213 | |
| 214 | } |
| 215 | //woo_chatbot load control handler. |
| 216 | function woo_chatbot_load_controlling(){ |
| 217 | $woo_chatbot_load=true; |
| 218 | if(woo_chatbot_is_mobile()&& get_option('disable_woo_chatbot_on_mobile')==1){ |
| 219 | $woo_chatbot_load=false; |
| 220 | } |
| 221 | return $woo_chatbot_load; |
| 222 | } |
| 223 | //checking Devices |
| 224 | function woo_chatbot_is_mobile(){ |
| 225 | $useragent=$_SERVER['HTTP_USER_AGENT']; |
| 226 | 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))){ |
| 227 | return true; |
| 228 | }else{ |
| 229 | return false; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 |