cart->add_to_cart( $product_id, $quantity ) ) { do_action( 'woocommerce_ajax_added_to_cart', $product_id ); WC_AJAX::get_refreshed_fragments(); } else { $this->json_headers(); // If there was an error adding to the cart, redirect to the product page to show any errors $data = array( 'error' => true, 'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id ) ); echo json_encode( $data ); } die(); } } /*********************************** END ADD TO CART AJAX ****************************************/ /********************************** BEGIN FILTER AJAX ************************************/ if(!function_exists('sv_filter_price')){ function sv_filter_price($min,$max,$filtered_posts = array()){ global $wpdb; $matched_products = array( 0 ); $matched_products_query = apply_filters( 'woocommerce_price_filter_results', $wpdb->get_results( $wpdb->prepare(" SELECT DISTINCT ID, post_parent, post_type FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ID = post_id WHERE post_type IN ( 'product', 'product_variation' ) AND post_status = 'publish' AND meta_key = %s AND meta_value BETWEEN %d AND %d ", '_price', $min, $max ), OBJECT_K ), $min, $max ); if ( $matched_products_query ) { foreach ( $matched_products_query as $product ) { if ( $product->post_type == 'product' ) $matched_products[] = $product->ID; if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) ) $matched_products[] = $product->post_parent; } } // Filter the id's if ( sizeof( $filtered_posts ) == 0) { $filtered_posts = $matched_products; } else { $filtered_posts = array_intersect( $filtered_posts, $matched_products ); } return $filtered_posts; } } add_action( 'wp_ajax_filter_product', 'sv_filter_product' ); add_action( 'wp_ajax_nopriv_filter_product', 'sv_filter_product' ); if(!function_exists('sv_filter_product')){ function sv_filter_product() { $data_filter = $_POST['data_filter']; $number = $_POST['number']; $order = $_POST['order']; $order_by = $_POST['orderby']; $pre = $_POST['pre']; $tab_is = $_POST['tab_is']; $product_type = $_POST['product_type']; // var_dump($data_filter); $tabs_list = $data_filter['tab_list']; $custom_list = array(); $html = ''; $args = array( 'post_type' => 'product', 'posts_per_page' => $number, 'orderby' => $order_by, 'order' => $order, ); $args['paged'] = 1; if($product_type == 'mostview'){ $args['meta_key'] = 'post_views'; $args['orderby'] = 'meta_value_num'; } if($product_type == 'bestsell'){ $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; } if($product_type == 'featured'){ $args['meta_key'] = '_featured'; $args['meta_value'] = 'yes'; } $tax_query = array(); foreach ($data_filter as $key => $value) { if($key != 'category' && $key != 'tab_list' && $key != 'price'){ $tax_query = array(); $tax_query['relation'] = 'AND'; $args['meta_query'] = array(array( 'key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN' )); $tax_query[] = array( 'taxonomy' => 'pa_'.$key, 'terms' => $value, 'field' => 'slug', 'operator' => 'IN' ); } if($key == 'category'){ $tax_query[]=array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $value ); } } if(isset($data_filter['price'])){ if(!empty($data_filter['price'])){ $price_filter = explode(',', $data_filter['price']); $min = $price_filter[0]; $max = $price_filter[1]; $args['post__in'] = sv_filter_price($min,$max); } } foreach ($tabs_list as $key => $item_slug) { $f_class = ''; if($key == 0) $f_class = 'active'; $term = get_term_by( 'slug',$item_slug, $tab_is ); $args['tax_query'] = array(); $args['tax_query']['relation'] = 'AND'; $args['tax_query'][]=array( 'taxonomy' => $tab_is, 'field' => 'slug', 'terms' => $item_slug ); $args['tax_query'] = array_merge($tax_query,$args['tax_query']); // var_dump($args); $product_query = new WP_Query($args); $count_query = $product_query->post_count; $max_page = $product_query->max_num_pages; $html .= '
'; if($max_page >1){ $html .= '
'; } $html .= '
'; } wp_reset_postdata(); echo balanceTags($html); } } add_action( 'wp_ajax_filter_product2', 'sv_filter_product2' ); add_action( 'wp_ajax_nopriv_filter_product2', 'sv_filter_product2' ); if(!function_exists('sv_filter_product2')){ function sv_filter_product2() { $data_filter = $_POST['data_filter']; $number = $_POST['number']; $order = $_POST['order']; $order_by = $_POST['orderby']; $product_type = $_POST['product_type']; $tabs_list = $data_filter['tab_list']; $tab_special_style = $_POST['style']; $html = ''; $args = array( 'post_type' => 'product', 'posts_per_page' => $number, 'orderby' => $order_by, 'order' => $order, ); $args['paged'] = 1; if($product_type == 'mostview'){ $args['meta_key'] = 'post_views'; $args['orderby'] = 'meta_value_num'; } if($product_type == 'bestsell'){ $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; } if($product_type == 'featured'){ $args['meta_key'] = '_featured'; $args['meta_value'] = 'yes'; } $tax_query = array(); foreach ($data_filter as $key => $value) { if($key != 'category' && $key != 'tab_list' && $key != 'price'){ $tax_query = array(); $tax_query['relation'] = 'AND'; $args['meta_query'] = array(array( 'key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN' )); $tax_query[] = array( 'taxonomy' => 'pa_'.$key, 'terms' => $value, 'field' => 'slug', 'operator' => 'IN' ); } if($key == 'category'){ $tax_query[]=array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $value ); } } $args['tax_query'] = $tax_query; if(isset($data_filter['price'])){ if(!empty($data_filter['price'])){ $price_filter = explode(',', $data_filter['price']); $min = $price_filter[0]; $max = $price_filter[1]; $args['post__in'] = sv_filter_price($min,$max); } } foreach ($tabs_list as $key => $item_slug) { $f_class = ''; if($key == 0) $f_class = 'active'; unset($args['meta_key']); unset($args['orderby']); unset($args['meta_query']); unset($args['meta_value']); if($item_slug == "bestseller"){ $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; } if($item_slug == "onsale"){ $args['meta_query'][]=array( 'key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ); } if($item_slug == "featured"){ $args['meta_key'] = '_featured'; $args['meta_value'] = 'yes'; } // var_dump($args); $args2 = $args; $args2['posts_per_page'] = 4; $product_query2 = new WP_Query($args2); $max_page_ajax = $product_query2->max_num_pages; $product_query = new WP_Query($args); $count_query = $product_query->post_count; $max_page = $product_query->max_num_pages; $html .= '
'; if($max_page > 1){ $html .= ''; } $html .= '
'; } wp_reset_postdata(); echo balanceTags($html); } } /*********************************** END FILTER AJAX ****************************************/ /********************************** LOAD PAGE AJAX ************************************/ add_action( 'wp_ajax_load_page_product', 'sv_load_page_product' ); add_action( 'wp_ajax_nopriv_load_page_product', 'sv_load_page_product' ); if(!function_exists('sv_load_page_product')){ function sv_load_page_product() { $data_filter = $_POST['data_filter']; $number = $_POST['number']; $order = $_POST['order']; $order_by = $_POST['orderby']; $tab_is = $_POST['tab_is']; $tab_value = $_POST['tab_value']; $paged = $_POST['paged']; $tabs_list = $data_filter['tab_list']; $product_type = $_POST['product_type']; $html = ''; $args = array( 'post_type' => 'product', 'posts_per_page' => $number, 'orderby' => $order_by, 'order' => $order, ); if($product_type == 'mostview'){ $args['meta_key'] = 'post_views'; $args['orderby'] = 'meta_value_num'; } if($product_type == 'bestsell'){ $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; } if($product_type == 'featured'){ $args['meta_key'] = '_featured'; $args['meta_value'] = 'yes'; } $args['paged'] = $paged; $tax_query = array(); foreach ($data_filter as $key => $value) { if($key != 'category' && $key != 'tab_list' && $key != 'price'){ $tax_query = array(); $tax_query['relation'] = 'AND'; $args['meta_query'] = array(array( 'key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN' )); $tax_query[] = array( 'taxonomy' => 'pa_'.$key, 'terms' => $value, 'field' => 'slug', 'operator' => 'IN' ); } if($key == 'category'){ $tax_query[]=array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $value ); } } if(isset($data_filter['price'])){ if(!empty($data_filter['price'])){ $price_filter = explode(',', $data_filter['price']); $min = $price_filter[0]; $max = $price_filter[1]; $args['post__in'] = sv_filter_price($min,$max); } } $term = get_term_by( 'slug',$tab_value, $tab_is ); $args['tax_query'] = array(); $args['tax_query']['relation'] = 'AND'; $args['tax_query'][]=array( 'taxonomy' => $tab_is, 'field' => 'slug', 'terms' => $tab_value ); $args['tax_query'] = array_merge($tax_query,$args['tax_query']); // var_dump($args); $product_query = new WP_Query($args); $count_query = $product_query->post_count; if($product_query->have_posts()) { while($product_query->have_posts()) { $product_query->the_post(); global $product,$post; $thumb_html = ''; if(has_post_thumbnail(get_the_ID())) $thumb_html = get_the_post_thumbnail(get_the_ID(),array(270,270),array('class'=>'img-responsive'));''; $html .= '
  • '.$product->get_price_html().'

    '.get_the_title().'

    '.substr(get_the_excerpt(),0,70).'..

    '.sv_get_rating_html().' '.sv_product_link_filter().'
  • '; } } wp_reset_postdata(); echo balanceTags($html); } } add_action( 'wp_ajax_load_more_product', 'sv_load_more_product' ); add_action( 'wp_ajax_nopriv_load_more_product', 'sv_load_more_product' ); if(!function_exists('sv_load_more_product')){ function sv_load_more_product() { $data_filter = $_POST['data_filter']; $number = $_POST['number']; $order = $_POST['order']; $order_by = $_POST['orderby']; // $max_page = $_POST['max_page']; $max_page_ajax = $_POST['max_page_ajax']; $paged = $_POST['paged']; $tabs_list = $data_filter['tab_list']; $item_slug = $_POST['item_slug']; $tab_special_style = $_POST['style']; $html = ''; if($paged < $max_page_ajax){ if($paged == 1){ if($number <= 4) $cr_paged = $paged +1; else{ if($number % 4 == 0) $cr_paged = $number/4 +1; else $cr_paged = (int)($number/4) + 2; } } else $cr_paged = $paged +1; $args = array( 'post_type' => 'product', 'posts_per_page' => 4, 'orderby' => $order_by, 'order' => $order, ); $args['paged'] = $cr_paged; $tax_query = array(); foreach ($data_filter as $key => $value) { if($key != 'category' && $key != 'tab_list' && $key != 'price'){ $tax_query = array(); $tax_query['relation'] = 'AND'; $args['meta_query'] = array(array( 'key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN' )); $tax_query[] = array( 'taxonomy' => 'pa_'.$key, 'terms' => $value, 'field' => 'slug', 'operator' => 'IN' ); } if($key == 'category'){ $tax_query[]=array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $value ); } } if(isset($data_filter['price'])){ if(!empty($data_filter['price'])){ $price_filter = explode(',', $data_filter['price']); $min = $price_filter[0]; $max = $price_filter[1]; $args['post__in'] = sv_filter_price($min,$max); } } if($item_slug == "bestseller"){ $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; } if($item_slug == "onsale"){ $args['meta_query'][]=array( 'key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric' ); } if($item_slug == "featured"){ $args['meta_key'] = '_featured'; $args['meta_value'] = 'yes'; } $args['tax_query'] = $tax_query; // var_dump($args); $product_query = new WP_Query($args); $count_query = $product_query->post_count; $max_page_new = $product_query->max_num_pages; if($product_query->have_posts()) { while($product_query->have_posts()) { $product_query->the_post(); global $product,$post; $thumb_html = ''; if(has_post_thumbnail(get_the_ID())) $thumb_html = get_the_post_thumbnail(get_the_ID(),array(270,270),array('class'=>'img-responsive'));''; $html .= '
  • '; if($tab_special_style == 'style2'){ $html .= '

    '.get_the_title().'

    '.$product->get_price_html().'
    '.sv_product_link_filter($tab_special_style); } else{ $html .= '
    '.$product->get_price_html().'

    '.get_the_title().'

    '.substr(get_the_excerpt(),0,70).'..

    '.sv_get_rating_html().' '.sv_product_link_filter($tab_special_style); } $html .= '
  • '; } } } wp_reset_postdata(); echo balanceTags($html); } } /*********************************** END LOAD PAGE AJAX ****************************************/ /********************************** REMOVE ITEM MINICART AJAX ************************************/ add_action( 'wp_ajax_product_remove', 'sv_product_remove' ); add_action( 'wp_ajax_nopriv_product_remove', 'sv_product_remove' ); if(!function_exists('sv_product_remove')){ function sv_product_remove() { global $wpdb, $woocommerce; $cart_item_key = $_POST['cart_item_key']; if ( $woocommerce->cart->get_cart_item( $cart_item_key ) ) { $woocommerce->cart->remove_cart_item( $cart_item_key ); } exit(); } } //remove woo breadcrumbs add_action( 'init','sv_remove_wc_breadcrumbs' ); // Remove page title add_filter( 'woocommerce_show_page_title', 'sv_remove_page_title'); // remove action wrap main content remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); // Custom wrap main content add_action('woocommerce_before_main_content', 'sv_add_before_main_content', 10); add_action('woocommerce_after_main_content', 'sv_add_after_main_content', 10); remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 ); function sv_add_before_main_content() { global $check_sidebar; $check_sidebar = false; $sidebar = sv_get_sidebar(); $sidebar_pos = $sidebar['position']; $type = 'grid';$el_class = 'product-grid'; if(isset($_GET['type'])){ $type = $_GET['type']; } if($type == 'list') $el_class = 'product-list'; $main_class = 'col-md-12 none-sidebar '.$el_class; if($sidebar_pos != 'no'){ $main_class = 'col-md-9 col-sm-8 col-xs-12 has-sidebar '.$el_class; $check_sidebar = true; } $col_class = 'shop-width-'.sv_get_option('woo_shop_column',4); ?>
    'product', 'post__in' => array($product_id) )); if( $query->have_posts() ): echo '
    '; while ( $query->have_posts() ) : $query->the_post(); global $post,$product,$woocommerce; sv_product_main_detai(true); endwhile; echo '
    '; endif; wp_reset_postdata(); } } //Custom woo shop column add_filter( 'loop_shop_columns', 'sv_woo_shop_columns', 1, 10 ); function sv_woo_shop_columns( $number_columns ) { $col = sv_get_option('woo_shop_column',4); return $col; } add_filter( 'loop_shop_per_page', 'sv_woo_shop_number', 20 ); function sv_woo_shop_number( $number) { $col = sv_get_option('woo_shop_number',12); return $col; } }