Example #1
0
 /**
  * Widget ajax listener
  */
 public static function listener()
 {
     global $wp_query, $wp_rewrite;
     $br_options = apply_filters('berocket_aapf_listener_br_options', get_option('br_filters_options'));
     add_filter('post_class', array(__CLASS__, 'add_product_class'));
     add_filter('woocommerce_pagination_args', array(__CLASS__, 'pagination_args'));
     $args = apply_filters('berocket_aapf_listener_wp_query_args', array());
     $args['post__in'] = BeRocket_AAPF::limits_filter(array());
     $args['post__in'] = BeRocket_AAPF::price_filter($args['post__in']);
     $args['post_status'] = 'publish';
     $args['post_type'] = 'product';
     $args['post__in'] = BeRocket_AAPF::price_filter($args['post__in']);
     $wp_query = new WP_Query($args);
     // here we get max products to know if current page is not too big
     if ($wp_rewrite->using_permalinks() and preg_match("~/page/([0-9]+)~", $_POST['location'], $mathces) or preg_match("~paged?=([0-9]+)~", $_POST['location'], $mathces)) {
         $args['paged'] = min($mathces[1], $wp_query->max_num_pages);
         $wp_query = new WP_Query($args);
     }
     ob_start();
     if ($wp_query->have_posts()) {
         do_action('woocommerce_before_shop_loop');
         woocommerce_product_loop_start();
         woocommerce_product_subcategories();
         while (have_posts()) {
             the_post();
             wc_get_template_part('content', 'product');
         }
         woocommerce_product_loop_end();
         do_action('woocommerce_after_shop_loop');
         wp_reset_postdata();
         $_RESPONSE['products'] = ob_get_contents();
     } else {
         echo apply_filters('berocket_aapf_listener_no_products_message', "<div class='no-products" . ($br_options['no_products_class'] ? ' ' . $br_options['no_products_class'] : '') . "'>" . $br_options['no_products_message'] . "</div>");
         $_RESPONSE['no_products'] = ob_get_contents();
     }
     ob_end_clean();
     echo json_encode($_RESPONSE);
     die;
 }
Example #2
0
 /**
  * Public function to get plugin's template
  *
  * @param string $name Template name to search for
  *
  * @return void
  */
 function br_get_template_part($name = '')
 {
     BeRocket_AAPF::br_get_template_part($name);
 }
/**
 * Widget ajax listener
 */
function tb_listener()
{
    global $wp_query, $wp_rewrite;
    add_filter('post_class', 'add_product_class');
    add_filter('woocommerce_pagination_args', 'pagination_args');
    $args = apply_filters('tb_listener_wp_query_args', array());
    if (!isset($args['post__in'])) {
        $args['post__in'] = array();
    }
    $woocommerce_hide_out_of_stock_items = BeRocket_AAPF_Widget::woocommerce_hide_out_of_stock_items();
    if ($woocommerce_hide_out_of_stock_items == 'yes') {
        $args['post__in'] = BeRocket_AAPF::remove_out_of_stock($args['post__in']);
    }
    $args['post__in'] = BeRocket_AAPF::remove_hidden($args['post__in']);
    $args['post__in'] = BeRocket_AAPF::limits_filter($args['post__in']);
    $args['post__in'] = BeRocket_AAPF::price_filter($args['post__in']);
    $args['post_status'] = 'publish';
    $args['post_type'] = 'product';
    $args['post__in'] = BeRocket_AAPF::price_filter($args['post__in']);
    $default_posts_per_page = get_option('posts_per_page');
    $args['posts_per_page'] = apply_filters('loop_shop_per_page', $default_posts_per_page);
    unset($default_posts_per_page);
    $wp_query = new WP_Query($args);
    // here we get max products to know if current page is not too big
    if ($wp_rewrite->using_permalinks() and preg_match("~/page/([0-9]+)~", $_POST['location'], $mathces) or preg_match("~paged?=([0-9]+)~", $_POST['location'], $mathces)) {
        $args['paged'] = min($mathces[1], $wp_query->max_num_pages);
        $wp_query = new WP_Query($args);
    }
    unset($args);
    ob_start();
    if ($wp_query->have_posts()) {
        do_action('woocommerce_before_shop_loop');
        woocommerce_product_loop_start();
        woocommerce_product_subcategories();
        while (have_posts()) {
            the_post();
            wc_get_template_part('content', 'product');
        }
        woocommerce_product_loop_end();
        do_action('woocommerce_after_shop_loop');
        wp_reset_postdata();
        $_RESPONSE['products'] = ob_get_contents();
    } else {
        wc_get_template('loop/no-products-found.php');
        $_RESPONSE['no_products'] = ob_get_contents();
    }
    ob_end_clean();
    echo json_encode($_RESPONSE);
    die;
}