예제 #1
0
    function snpshpwp_products_category($atts, $content = null)
    {
        extract(shortcode_atts(array('ids' => '', 'rows' => 1, 'columns' => '4', 'orderby' => 'date', 'order' => 'DESC', 'meta_key' => '', 'ajax' => 'yes', 'pagination' => 'yes', 'bot_margin' => 36, 'class' => '', 'shortcode_id' => '', 'animate' => 'none', 'animation_delay' => 0, 'animation_group' => ''), $atts));
        if ($ids == '') {
            return __('Please select categories', 'snpshpwp');
        }
        $exploded = explode(',', $ids);
        global $paged;
        $args = array();
        if (empty($paged)) {
            $paged = 1;
        }
        if (isset($_GET['orderby'])) {
            if ($_GET['orderby'] == 'price' || $_GET['orderby'] == 'price-desc') {
                $orderby = 'meta_value_num';
                $order = $_GET['orderby'] == 'price' ? 'ASC' : 'DESC';
                $args = array('meta_key' => '_price');
            } else {
                if ($_GET['orderby'] == 'rating') {
                    add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
                } else {
                    if ($_GET['orderby'] == 'popularity') {
                        $orderby = 'meta_value_num';
                        $order = 'DESC';
                        $args = array('meta_key' => 'total_sales');
                    } else {
                        if ($_GET['orderby'] == 'menu_order') {
                            $orderby = $orderby;
                        } else {
                            $orderby = $_GET['orderby'];
                        }
                    }
                }
            }
        }
        if (isset($_GET['min_price']) && isset($_GET['max_price'])) {
            $orderby = 'meta_value_num';
            $order = 'ASC';
            $args['meta_query'] = array(array('key' => '_price', 'value' => array(floatval($_GET['min_price']), floatval($_GET['max_price'])), 'type' => 'numeric', 'compare' => 'BETWEEN'));
        }
        if (isset($_GET['product_tag'])) {
            $args = array_merge($args, array('product_tag' => $_GET['product_tag']));
        }
        if (isset($_GET['characteristics'])) {
            $args = array_merge($args, array('characteristics' => $_GET['characteristics']));
        }
        if (isset($_GET['sale_products'])) {
            $meta_query = array(array('key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric'));
            $args['meta_query'] = $meta_query;
        }
        if (isset($_GET['product_cat'])) {
            $args = $args + array('tax_query' => array(array('taxonomy' => 'product_cat', 'terms' => array($_GET['product_cat']), 'field' => 'slug', 'operator' => 'IN')));
        } else {
            if ($ids !== '0') {
                $args = $args + array('tax_query' => array(array('taxonomy' => 'product_cat', 'terms' => $exploded, 'field' => 'slug', 'operator' => 'IN')));
            }
        }
        foreach ($_GET as $k => $v) {
            if (strpos($k, 'pa_') !== false) {
                $args = $args + array('tax_query' => array(array('taxonomy' => $k, 'terms' => $v, 'field' => 'slug', 'operator' => 'IN')));
            }
        }
        if (!isset($args['meta_query'])) {
            $args['meta_query'] = WC()->query->get_meta_query();
        }
        $args = $args + array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $orderby, 'order' => $order, 'posts_per_page' => $columns * $rows, 'paged' => $paged, 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
        if (!isset($args['meta_query'])) {
            $args['meta_query'] = WC()->query->get_meta_query();
        }
        $query_string_ajax = http_build_query($args);
        $bot_margin = (int) $bot_margin;
        $margin = " style='margin-bottom" . $bot_margin . "px'";
        $out = '';
        $html_pag = '';
        global $woocommerce, $woocommerce_loop;
        $woocommerce_loop['columns'] = $columns;
        $products = new WP_Query($args);
        if ($pagination == 'true') {
            $html_pag = snpshpwp_mini_woo_pagination($products->max_num_pages, $paged, 3, $ajax);
        }
        ob_start();
        if ($products->have_posts()) {
            ?>

		<?php 
            wc_get_template('loop/orderby.php');
            ?>

		<?php 
            woocommerce_product_loop_start();
            ?>

			<?php 
            while ($products->have_posts()) {
                $products->the_post();
                ?>

				<?php 
                wc_get_template_part('content', 'product');
                ?>

			<?php 
            }
            ?>

		<?php 
            woocommerce_product_loop_end();
            ?>

	<?php 
        }
        wp_reset_postdata();
        $shortcode = ob_get_clean();
        $out .= do_shortcode($shortcode) . $html_pag;
        if ($animate != 'none') {
            $animate = ' frb_animated frb_' . $animate . '"';
            if ($animation_delay != 0) {
                $animation_delay = (int) $animation_delay;
                $animate .= ' data-adelay="' . $animation_delay . '"';
            }
            if ($animation_group != '') {
                $animate .= ' data-agroup="' . $animation_group . '"';
            }
        } else {
            $animate = '"';
        }
        $html_animated = '<div ' . ($shortcode_id != '' ? 'id="' . $shortcode_id . '"' : '') . ' class="snpshpwp_woo_wrap div_touch_optimized snpshpwp_div_inherit_width ' . $class . $animate . ' style="padding-bottom:' . $bot_margin . 'px !important;" data-string="' . $query_string_ajax . '" data-shortcode="' . $margin . '|' . $columns . '|' . $pagination . '|' . $ajax . '">' . $out . '</div>';
        return $html_animated;
    }
예제 #2
0
    function snpshpwp_ajaxload_send_woo()
    {
        global $woocommerce, $woocommerce_loop;
        $query_string = $_POST['data'];
        $current_page = snpshpwp_get_between($query_string, 'paged=', '&');
        $page = $_POST['page'];
        $ajax = $_POST['ajax'];
        $bot_margin = $_POST['bot_margin'];
        $columns = $_POST['columns'];
        $args = str_replace('paged=' . $current_page . '&', 'paged=' . $page . '&', $query_string);
        $woocommerce_loop['columns'] = $columns;
        ob_start();
        $products = new WP_Query($args);
        if ($products->have_posts()) {
            ?>

		<?php 
            woocommerce_product_loop_start();
            ?>

			<?php 
            while ($products->have_posts()) {
                $products->the_post();
                ?>


				<?php 
                woocommerce_get_template_part('content', 'product');
                ?>

			<?php 
            }
            // end of the loop.
            ?>

		<?php 
            woocommerce_product_loop_end();
            ?>

	<?php 
        }
        wp_reset_postdata();
        die('<div class="woocommerce">' . ob_get_clean() . '</div>' . snpshpwp_mini_woo_pagination($products->max_num_pages, $page, 1, $ajax));
    }