当前位置: 首页>>代码示例>>PHP>>正文


PHP wc_get_product_ids_on_sale函数代码示例

本文整理汇总了PHP中wc_get_product_ids_on_sale函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_get_product_ids_on_sale函数的具体用法?PHP wc_get_product_ids_on_sale怎么用?PHP wc_get_product_ids_on_sale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wc_get_product_ids_on_sale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sale_products

 public static function sale_products($atts)
 {
     global $woocommerce_loop, $woocommerce;
     $atts = shortcode_atts(array("title" => '', "item_style" => 'grid', "is_slider" => '0', "per_page" => '12', "columns" => '4', "orderby" => 'title', "order" => 'asc', "as_widget" => 0, "excerpt_limit" => 10, "hide_free" => 0, "show_hidden" => 0), $atts);
     $product_ids_on_sale = wc_get_product_ids_on_sale();
     //$meta_query = WC()->query->get_meta_query();
     $args = array('posts_per_page' => $atts['per_page'], 'orderby' => $atts['orderby'], 'order' => $atts['order'], 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'meta_query' => array(), 'post__in' => array_merge(array(0), $product_ids_on_sale));
     if (absint($atts['as_widget'])) {
         if (!absint($atts['show_hidden'])) {
             $args['meta_query'][] = WC()->query->visibility_meta_query();
             $args['post_parent'] = 0;
         }
         if (absint($atts['hide_free'])) {
             $args['meta_query'][] = array('key' => '_price', 'value' => 0, 'compare' => '>', 'type' => 'DECIMAL');
         }
     } else {
         $args['meta_query'] = WC()->query->get_meta_query();
     }
     ob_start();
     $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
     $old_columns = $woocommerce_loop['columns'];
     if ($products->have_posts()) {
         self::get_template('shortcode-woo-nomal.tpl.php', $atts, $products);
     }
     wp_reset_postdata();
     $woocommerce_loop['columns'] = $old_columns;
     $classes = self::pareShortcodeClass('columns-' . absint($atts['columns']));
     return '<div class="' . esc_attr(implode(' ', $classes)) . '">' . ob_get_clean() . '</div>';
 }
开发者ID:kinhdon2011,项目名称:nexthemes-plugins,代码行数:29,代码来源:class-woo-shortcodes.php

示例2: content

    protected function content($atts, $content = null)
    {
        $atts = function_exists('vc_map_get_attributes') ? vc_map_get_attributes('lastest_deals_sidebar', $atts) : $atts;
        $atts = shortcode_atts(array('title' => '', 'taxonomy' => '', 'number' => 12, 'autoplay' => "false", 'navigation' => "false", 'slidespeed' => 250, 'loop' => "false", 'items' => 1, 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
        extract($atts);
        $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'latest-deals ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '));
        $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
        $elementClass = apply_filters('kt_lastest_deals_sidebar_class_container', $elementClass);
        // Get products on sale
        $product_ids_on_sale = wc_get_product_ids_on_sale();
        $meta_query = WC()->query->get_meta_query();
        $args = array('posts_per_page' => $number, 'post_type' => 'product', 'orderby' => 'meta_value_num', 'meta_key' => '_sale_price_dates_to', 'order' => 'DESC', 'no_found_rows' => 1, 'post_status' => 'publish', 'meta_query' => $meta_query, 'post__in' => array_merge(array(0), $product_ids_on_sale));
        if ($taxonomy) {
            $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => explode(",", $taxonomy)));
        }
        $q = apply_filters('woocommerce_shortcode_products_query', $args, $atts);
        $query = new WP_Query($q);
        global $woocommerce_loop;
        ob_start();
        if ($query->have_posts()) {
            $data_carousel = array("autoplay" => $autoplay, "navigation" => $navigation, "slidespeed" => $slidespeed, "autoheight" => "false", "loop" => $loop, "dots" => "false", 'nav' => "true", "autoplayTimeout" => 1000, "autoplayHoverPause" => "true", 'items' => 1);
            add_filter("woocommerce_get_price_html_from_to", "kt_get_price_html_from_to", 10, 4);
            add_filter('woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2);
            ?>
            <div class="<?php 
            echo esc_attr($elementClass);
            ?>
">
                <h2 class="latest-deal-title"><?php 
            echo esc_html($title);
            ?>
</h2>
                <div class="latest-deal-content">
                    <ul class="product-list owl-carousel" <?php 
            echo _data_carousel($data_carousel);
            ?>
>
                        <?php 
            add_filter("woocommerce_get_price_html_from_to", "kt_get_price_html_from_to", 10, 4);
            while ($query->have_posts()) {
                $query->the_post();
                wc_get_template_part('content', 'product-sidebar');
            }
            // end of the loop.
            remove_filter("woocommerce_get_price_html_from_to", "kt_get_price_html_from_to", 10, 4);
            ?>
                    </ul>
                </div>
            </div>
            <?php 
            remove_filter("woocommerce_get_price_html_from_to", "kt_get_price_html_from_to", 10, 4);
            remove_filter('woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2);
        }
        wp_reset_postdata();
        wp_reset_query();
        $result = ob_get_contents();
        ob_clean();
        return $result;
    }
开发者ID:hikaram,项目名称:wee,代码行数:59,代码来源:lastest_deals_sidebar.php

示例3: content

    protected function content($atts, $content = null)
    {
        $atts = function_exists('vc_map_get_attributes') ? vc_map_get_attributes('list_product', $atts) : $atts;
        $atts = shortcode_atts(array('title' => '', 'cat' => 0, 'number' => 4, 'types' => 'sale', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
        extract($atts);
        global $woocommerce_loop;
        $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'popular-tabs ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '));
        $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
        ob_start();
        $meta_query = WC()->query->get_meta_query();
        $query = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $number, 'meta_query' => $meta_query);
        global $woocommerce_loop;
        $woocommerce_loop['columns'] = $number;
        if ($cat > 0) {
            $query['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $cat));
        }
        if ($types == 'arrival') {
            $query['orderby'] = 'date';
            $query['order'] = 'DESC';
        }
        if ($types == 'sale') {
            $product_ids_on_sale = wc_get_product_ids_on_sale();
            $query['meta_key'] = 'total_sales';
            $query['orderby'] = 'meta_value_num';
            $query['post__in'] = array_merge(array(0), $product_ids_on_sale);
        }
        if ($types == 'review') {
            add_filter('posts_clauses', array($this, 'order_by_rating_post_clauses'));
        }
        $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $query, $atts));
        if ($types == 'review') {
            remove_filter('posts_clauses', array($this, 'order_by_rating_post_clauses'));
        }
        if ($products->have_posts()) {
            ?>
        <div class="mega-group">
            <h4 class="mega-group-header"><span><?php 
            echo esc_html($title);
            ?>
</span></h4>
            <div class="mega-products">
                <?php 
            while ($products->have_posts()) {
                $products->the_post();
                ?>
                    <?php 
                wc_get_template_part('content', 'product-verticalmenu');
                ?>
                <?php 
            }
            // end of the loop.
            ?>
            </div>
        </div>  
        <?php 
        }
        return ob_get_clean();
    }
开发者ID:hikaram,项目名称:wee,代码行数:58,代码来源:list_product.php

示例4: content

 protected function content($atts, $content = null)
 {
     $atts = shortcode_atts(array('product_type' => 'classic', 'product_effect' => '', 'desktop' => 4, 'per_page' => 10, 'orderby' => 'date', 'meta_key' => '', 'order' => 'DESC', 'source' => 'all', 'categories' => '', 'products' => '', 'operator' => 'IN', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
     extract($atts);
     $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'cruxstore-products', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'product_stype' => 'cruxstore-products-' . $product_type, 'woocommerce' => 'woocommerce columns-' . $desktop);
     $meta_query = WC()->query->get_meta_query();
     if ($source == 'best-sellers') {
         $meta_key = 'total_sales';
         $orderby = 'meta_value_num';
     }
     $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'meta_query' => $meta_query, 'order' => $order, 'orderby' => $orderby, 'meta_key' => $meta_key);
     if ($source == 'onsale') {
         $product_ids_on_sale = wc_get_product_ids_on_sale();
         $args['post__in'] = array_merge(array(0), $product_ids_on_sale);
     } elseif ($source == 'featured') {
         $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
     } elseif ($source == 'top-rated') {
         add_filter('posts_clauses', array(__CLASS__, 'order_by_rating_post_clauses'));
     } elseif ($source == 'categories') {
         if (!empty($categories)) {
             $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array_map('sanitize_title', explode(',', $categories)), 'field' => 'slug', 'operator' => $operator));
         }
     } elseif ($source == 'products') {
         if (!empty($atts['products'])) {
             $args['post__in'] = array_map('trim', explode(',', $atts['products']));
         }
     }
     $output = '';
     ob_start();
     global $woocommerce_loop;
     $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
     if ($product_type != 'classic') {
         $product_effect = '';
     }
     $woocommerce_loop['columns'] = $desktop;
     $woocommerce_loop['type'] = $product_type;
     $woocommerce_loop['effect'] = $product_effect;
     if ($products->have_posts()) {
         woocommerce_product_loop_start();
         if ($product_type == 'masonry') {
             echo '<div class="clearfix product col-sm-3 grid-sizer"></div>';
         }
         while ($products->have_posts()) {
             $products->the_post();
             wc_get_template_part('content', 'product');
         }
         // end of the loop.
         woocommerce_product_loop_end();
     }
     wp_reset_postdata();
     if ($source == 'top-rated') {
         remove_filter('posts_clauses', array(__CLASS__, 'order_by_rating_post_clauses'));
     }
     $output .= ob_get_clean();
     $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
     return '<div class="' . esc_attr($elementClass) . '">' . $output . '</div>';
 }
开发者ID:websideas,项目名称:Mondova,代码行数:57,代码来源:products.php

示例5: content

 protected function content($atts, $content = null)
 {
     $atts = shortcode_atts(array('per_page' => 10, 'orderby' => 'date', 'meta_key' => '', 'order' => 'DESC', 'source' => '', 'categories' => '', 'products' => '', 'operator' => 'IN', 'layout' => 'normal', 'autoheight' => true, 'autoplay' => false, 'mousedrag' => true, 'autoplayspeed' => 5000, 'slidespeed' => 200, 'carousel_skin' => '', 'desktop' => 4, 'desktopsmall' => 3, 'tablet' => 2, 'mobile' => 1, 'gutters' => false, 'navigation' => true, 'navigation_always_on' => false, 'navigation_position' => 'center-outside', 'navigation_style' => 'normal', 'pagination' => false, 'pagination_position' => 'center-bottom', 'pagination_style' => 'dot-stroke', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
     extract($atts);
     $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'products-carousel ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'woocommerce' => 'woocommerce columns-' . $desktop, 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'layout' => 'layout-' . $layout);
     $meta_query = WC()->query->get_meta_query();
     if ($source == 'best-sellers') {
         $meta_key = 'total_sales';
         $orderby = 'meta_value_num';
     }
     $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'meta_query' => $meta_query, 'order' => $order, 'orderby' => $orderby, 'meta_key' => $meta_key);
     if ($source == 'onsale') {
         $product_ids_on_sale = wc_get_product_ids_on_sale();
         $args['post__in'] = array_merge(array(0), $product_ids_on_sale);
     } elseif ($source == 'featured') {
         $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
     } elseif ($source == 'top-rated') {
         add_filter('posts_clauses', array(__CLASS__, 'order_by_rating_post_clauses'));
     } elseif ($source == 'categories') {
         if (!empty($categories)) {
             $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array_map('sanitize_title', explode(',', $categories)), 'field' => 'slug', 'operator' => $operator));
         }
     } elseif ($source == 'products') {
         if (!empty($atts['products'])) {
             $args['post__in'] = array_map('trim', explode(',', $atts['products']));
         }
     }
     $output = $carousel_html = '';
     ob_start();
     $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
     if ($products->have_posts()) {
         global $woocommerce_loop;
         $woocommerce_loop['columns'] = $desktop;
         $carousel_ouput = cruxstore_render_carousel(apply_filters('cruxstore_render_args', $atts), '', 'wc-carousel-wrapper');
         if ($layout == 'transparent') {
             $woocommerce_loop['type'] = 'transparent';
         } else {
             $woocommerce_loop['type'] = 'normal';
         }
         woocommerce_product_loop_start();
         while ($products->have_posts()) {
             $products->the_post();
             wc_get_template_part('content', 'product');
         }
         // end of the loop.
         woocommerce_product_loop_end();
     }
     $carousel_html .= ob_get_clean();
     wp_reset_postdata();
     if ($carousel_html) {
         $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
         $output = '<div class="' . esc_attr($elementClass) . '">' . str_replace('%carousel_html%', $carousel_html, $carousel_ouput) . '</div>';
     }
     return $output;
 }
开发者ID:websideas,项目名称:Mondova,代码行数:55,代码来源:products_carousel.php

示例6: test_wc_get_product_ids_on_sale

 /**
  * Test wc_get_product_ids_on_sale()
  *
  * @since 2.4
  */
 public function test_wc_get_product_ids_on_sale()
 {
     $this->assertEquals(array(), wc_get_product_ids_on_sale());
     delete_transient('wc_products_onsale');
     // Create product
     $product = \WC_Helper_Product::create_simple_product();
     update_post_meta($product->id, '_regular_price', wc_format_decimal(10));
     update_post_meta($product->id, '_price', wc_format_decimal(5));
     update_post_meta($product->id, '_sale_price', wc_format_decimal(5));
     $this->assertEquals(array($product->id), wc_get_product_ids_on_sale());
     // Delete Product
     \WC_Helper_Product::delete_product($product->id);
 }
开发者ID:nightbook,项目名称:woocommerce,代码行数:18,代码来源:functions.php

示例7: widget

 public function widget($args, $instance)
 {
     echo apply_filters('kt_wg_before_widget', $args['before_widget']);
     $title = isset($instance['title']) && $instance['title'] ? esc_html($instance['title']) : '';
     $number = isset($instance['number']) && intval($instance['number']) ? intval($instance['number']) : 3;
     $orderby = isset($instance['orderby']) && $instance['orderby'] ? esc_attr($instance['orderby']) : 'date';
     $order = isset($instance['order']) && $instance['order'] ? esc_attr($instance['order']) : 'desc';
     $meta_query = WC()->query->get_meta_query();
     $product_ids_on_sale = wc_get_product_ids_on_sale();
     $params = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $number, 'meta_query' => $meta_query, 'suppress_filter' => true, 'orderby' => $orderby, 'order' => $order, 'post__in' => array_merge(array(0), $product_ids_on_sale));
     $product = new WP_Query($params);
     if ($product->have_posts()) {
         ?>
     <!-- block best sellers -->
     <div class="block left-module">
         <?php 
         if ($title) {
             echo apply_filters('kt_wg_before_title', $args['before_title']);
             echo esc_html($title);
             echo apply_filters('kt_wg_after_title', $args['after_title']);
         }
         add_filter('woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2);
         add_filter("woocommerce_get_price_html_from_to", "kt_get_price_html_from_to", 10, 4);
         ?>
         <div class="block_content product-onsale">
             <ul class="product-list owl-carousel" data-loop="false" data-nav = "false" data-margin = "0" data-autoplayTimeout="1000" data-autoplayHoverPause = "true" data-items="1" data-autoplay="false">
                 <?php 
         while ($product->have_posts()) {
             $product->the_post();
             ?>
                     <li>
                         <?php 
             wc_get_template_part('content', 'on-sale-sidebar');
             ?>
                     </li>
                 <?php 
         }
         ?>
             </ul>
         </div>
         <?php 
         remove_filter("woocommerce_get_price_html_from_to", "kt_get_price_html_from_to", 10, 4);
         remove_filter('woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2);
         ?>
     </div>
     <!-- ./block best sellers  -->
     <?php 
     }
     echo apply_filters('kt_wg_after_widget', $args['after_widget']);
 }
开发者ID:k2jysy,项目名称:kshop,代码行数:50,代码来源:on-sale.php

示例8: get_products

 /**
  * Query woocommerce products and return them
  *
  * This is a modified version of woocommerce class-wc-widget-products.php
  * 
  * The modifications:
  * - category dropdown filter with product taxonomies
  *
  * @param  array $args
  * @param  array $instance
  * @return WP_Query
  */
 public function get_products($args, $instance)
 {
     $category = !empty($instance['category']) ? absint($instance['category']) : $this->settings['category']['std'];
     $number = !empty($instance['number']) ? absint($instance['number']) : $this->settings['number']['std'];
     $show = !empty($instance['show']) ? sanitize_title($instance['show']) : $this->settings['show']['std'];
     $orderby = !empty($instance['orderby']) ? sanitize_title($instance['orderby']) : $this->settings['orderby']['std'];
     $order = !empty($instance['order']) ? sanitize_title($instance['order']) : $this->settings['order']['std'];
     $query_args = array('tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $category)), 'posts_per_page' => $number, 'post_status' => 'publish', 'post_type' => 'product', 'no_found_rows' => 1, 'order' => $order, 'meta_query' => array());
     if (empty($instance['show_hidden'])) {
         $query_args['meta_query'][] = WC()->query->visibility_meta_query();
         $query_args['post_parent'] = 0;
     }
     if (!empty($instance['hide_free'])) {
         $query_args['meta_query'][] = array('key' => '_price', 'value' => 0, 'compare' => '>', 'type' => 'DECIMAL');
     }
     $query_args['meta_query'][] = WC()->query->stock_status_meta_query();
     $query_args['meta_query'] = array_filter($query_args['meta_query']);
     switch ($show) {
         case 'featured':
             $query_args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
             break;
         case 'onsale':
             $product_ids_on_sale = wc_get_product_ids_on_sale();
             $product_ids_on_sale[] = 0;
             $query_args['post__in'] = $product_ids_on_sale;
             break;
     }
     switch ($orderby) {
         case 'price':
             $query_args['meta_key'] = '_price';
             $query_args['orderby'] = 'meta_value_num';
             break;
         case 'rand':
             $query_args['orderby'] = 'rand';
             break;
         case 'sales':
             $query_args['meta_key'] = 'total_sales';
             $query_args['orderby'] = 'meta_value_num';
             break;
         default:
             $query_args['orderby'] = 'date';
     }
     $result = new WP_Query(apply_filters('smyck_widget_query_args', $query_args));
     return $result;
 }
开发者ID:raphaello77,项目名称:woocommerce-image-upload-and-product-listing-widget,代码行数:57,代码来源:image_product_listing_widget.php

示例9: get_products

 /**
  * Query the products and return them.
  * @param  array $args
  * @param  array $instance
  * @return WP_Query
  */
 public function get_products($args, $instance)
 {
     $number = !empty($instance['number']) ? absint($instance['number']) : $this->settings['number']['std'];
     $show = !empty($instance['show']) ? sanitize_title($instance['show']) : $this->settings['show']['std'];
     $orderby = !empty($instance['orderby']) ? sanitize_title($instance['orderby']) : $this->settings['orderby']['std'];
     $order = !empty($instance['order']) ? sanitize_title($instance['order']) : $this->settings['order']['std'];
     $product_visibility_term_ids = wc_get_product_visibility_term_ids();
     $query_args = array('posts_per_page' => $number, 'post_status' => 'publish', 'post_type' => 'product', 'no_found_rows' => 1, 'order' => $order, 'meta_query' => array(), 'tax_query' => array('relation' => 'AND'));
     if (empty($instance['show_hidden'])) {
         $query_args['tax_query'][] = array('taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', 'terms' => is_search() ? $product_visibility_term_ids['exclude-from-search'] : $product_visibility_term_ids['exclude-from-catalog'], 'operator' => 'NOT IN');
         $query_args['post_parent'] = 0;
     }
     if (!empty($instance['hide_free'])) {
         $query_args['meta_query'][] = array('key' => '_price', 'value' => 0, 'compare' => '>', 'type' => 'DECIMAL');
     }
     if ('yes' === get_option('woocommerce_hide_out_of_stock_items')) {
         $query_args['tax_query'] = array(array('taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', 'terms' => $product_visibility_term_ids['outofstock'], 'operator' => 'NOT IN'));
     }
     switch ($show) {
         case 'featured':
             $query_args['tax_query'][] = array('taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', 'terms' => $product_visibility_term_ids['featured']);
             break;
         case 'onsale':
             $product_ids_on_sale = wc_get_product_ids_on_sale();
             $product_ids_on_sale[] = 0;
             $query_args['post__in'] = $product_ids_on_sale;
             break;
     }
     switch ($orderby) {
         case 'price':
             $query_args['meta_key'] = '_price';
             $query_args['orderby'] = 'meta_value_num';
             break;
         case 'rand':
             $query_args['orderby'] = 'rand';
             break;
         case 'sales':
             $query_args['meta_key'] = 'total_sales';
             $query_args['orderby'] = 'meta_value_num';
             break;
         default:
             $query_args['orderby'] = 'date';
     }
     return new WP_Query(apply_filters('woocommerce_products_widget_query_args', $query_args));
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:51,代码来源:class-wc-widget-products.php

示例10: content

 protected function content($atts, $content = null)
 {
     $atts = shortcode_atts(array('desktop' => 3, 'per_page' => 10, 'orderby' => 'date', 'meta_key' => '', 'order' => 'DESC', 'source' => 'all', 'categories' => '', 'products' => '', 'operator' => 'IN', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
     extract($atts);
     $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'cruxstore-products-countdown', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'woocommerce' => 'woocommerce columns-' . $desktop, 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '));
     $meta_query = WC()->query->get_meta_query();
     $product_ids_on_sale = wc_get_product_ids_on_sale();
     $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $atts['per_page'], 'meta_query' => $meta_query, 'order' => $order, 'orderby' => $orderby, 'meta_key' => $meta_key, 'post__in' => array_merge(array(0), $product_ids_on_sale));
     if ($source == 'categories') {
         if (!empty($categories)) {
             $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array_map('sanitize_title', explode(',', $categories)), 'field' => 'slug', 'operator' => $operator));
         }
     } elseif ($source == 'products') {
         if (!empty($atts['products'])) {
             $args['post__in'] = array_map('trim', explode(',', $atts['products']));
         }
     }
     $output = '';
     ob_start();
     global $woocommerce_loop;
     $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
     $woocommerce_loop['columns'] = $desktop;
     $woocommerce_loop['type'] = 'countdown';
     if ($products->have_posts()) {
         woocommerce_product_loop_start();
         while ($products->have_posts()) {
             $products->the_post();
             wc_get_template_part('content', 'product_sale');
         }
         // end of the loop.
         woocommerce_product_loop_end();
     }
     wp_reset_postdata();
     $output .= ob_get_clean();
     $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
     return '<div class="' . esc_attr($elementClass) . '">' . $output . '</div>';
 }
开发者ID:websideas,项目名称:Mondova,代码行数:37,代码来源:products_sale_countdown.php

示例11: dhvc_woo_products_shortcode


//.........这里部分代码省略.........
            }
        }
        if ($query_type == 'related') {
            $query_args = $this->_get_related_product($query_args);
            if (empty($query_args)) {
                return;
            }
        }
        if ($query_type == 'crosssell') {
            $query_args = $this->_get_crosssell_product($query_args);
            if (empty($query_args)) {
                return;
            }
        }
        $query_args['meta_query'] = array();
        if ($show_hidden == '0') {
            $query_args['meta_query'][] = array('key' => '_visibility', 'value' => array('visible', 'catalog'), 'compare' => 'IN');
            $query_args['post_parent'] = 0;
        }
        if (!empty($hide_free)) {
            $query_args['meta_query'][] = array('key' => '_price', 'value' => 0, 'compare' => '>', 'type' => 'DECIMAL');
        }
        $stock_status = array();
        if (get_option('woocommerce_hide_out_of_stock_items') == 'yes') {
            $stock_status = array('key' => '_stock_status', 'value' => 'instock', 'compare' => '=');
        }
        $query_args['meta_query'][] = $stock_status;
        $query_args['meta_query'] = array_filter($query_args['meta_query']);
        switch ($show) {
            case 'featured':
                $query_args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
                break;
            case 'onsale':
                $product_ids_on_sale = wc_get_product_ids_on_sale();
                $product_ids_on_sale[] = 0;
                $query_args['post__in'] = $product_ids_on_sale;
                break;
        }
        if (isset($_GET['orderby']) && !empty($_GET['orderby'])) {
            $orderby = sanitize_text_field($_GET['orderby']);
        }
        $query_args['order'] = $order;
        switch ($orderby) {
            case 'title':
                $query_args['orderby'] = 'title';
                break;
            case 'modified':
                $query_args['orderby'] = 'modified';
                break;
            case 'comment_count':
                $query_args['orderby'] = 'comment_count';
                break;
            case 'popularity':
                $args['meta_key'] = 'total_sales';
                // Sorting handled later though a hook
                add_filter('posts_clauses', array($woocommerce->query, 'order_by_popularity_post_clauses'));
                break;
            case 'rating':
                // Sorting handled later though a hook
                add_filter('posts_clauses', array($woocommerce->query, 'order_by_rating_post_clauses'));
                break;
            case 'date':
                $query_args['orderby'] = 'date';
                //$query_args['order']    = 'ASC' ? 'ASC' : 'DESC';
                break;
            case 'rand':
开发者ID:jmead,项目名称:trucell-cms,代码行数:67,代码来源:class.php

示例12: is_valid_for_product

 /**
  * Check if a coupon is valid for a product.
  *
  * @param  WC_Product  $product
  * @return boolean
  */
 public function is_valid_for_product($product, $values = array())
 {
     if (!$this->is_type(wc_get_product_coupon_types())) {
         return apply_filters('woocommerce_coupon_is_valid_for_product', false, $product, $this, $values);
     }
     $valid = false;
     $product_cats = wc_get_product_cat_ids($product->id);
     // Specific products get the discount
     if (sizeof($this->product_ids) > 0) {
         if (in_array($product->id, $this->product_ids) || isset($product->variation_id) && in_array($product->variation_id, $this->product_ids) || in_array($product->get_parent(), $this->product_ids)) {
             $valid = true;
         }
     }
     // Category discounts
     if (sizeof($this->product_categories) > 0) {
         if (sizeof(array_intersect($product_cats, $this->product_categories)) > 0) {
             $valid = true;
         }
     }
     if (!sizeof($this->product_ids) && !sizeof($this->product_categories)) {
         // No product ids - all items discounted
         $valid = true;
     }
     // Specific product ID's excluded from the discount
     if (sizeof($this->exclude_product_ids) > 0) {
         if (in_array($product->id, $this->exclude_product_ids) || isset($product->variation_id) && in_array($product->variation_id, $this->exclude_product_ids) || in_array($product->get_parent(), $this->exclude_product_ids)) {
             $valid = false;
         }
     }
     // Specific categories excluded from the discount
     if (sizeof($this->exclude_product_categories) > 0) {
         if (sizeof(array_intersect($product_cats, $this->exclude_product_categories)) > 0) {
             $valid = false;
         }
     }
     // Sale Items excluded from discount
     if ($this->exclude_sale_items == 'yes') {
         $product_ids_on_sale = wc_get_product_ids_on_sale();
         if (isset($product->variation_id)) {
             if (in_array($product->variation_id, $product_ids_on_sale, true)) {
                 $valid = false;
             }
         } elseif (in_array($product->id, $product_ids_on_sale, true)) {
             $valid = false;
         }
     }
     return apply_filters('woocommerce_coupon_is_valid_for_product', $valid, $product, $this, $values);
 }
开发者ID:naveeninja,项目名称:woocommerce,代码行数:54,代码来源:class-wc-coupon.php

示例13: sf_product_items


//.........这里部分代码省略.........
        }
        // ARRAY ARGUMENTS
        if ($asset_type == "latest-products") {
            $args = array('post_type' => 'product', 'post_status' => 'publish', 'product_cat' => $category, 'ignore_sticky_posts' => 1, 'posts_per_page' => $item_count, 'orderby' => $order_by, 'order' => $order);
            $args['meta_query'] = array();
            $args['meta_query'][] = $woocommerce->query->stock_status_meta_query();
            $args['meta_query'][] = $woocommerce->query->visibility_meta_query();
        } else {
            if ($asset_type == "featured-products") {
                $args = array('post_type' => 'product', 'post_status' => 'publish', 'product_cat' => $category, 'ignore_sticky_posts' => 1, 'meta_key' => '_featured', 'meta_value' => 'yes', 'posts_per_page' => $item_count, 'orderby' => $order_by, 'order' => $order);
            } else {
                if ($asset_type == "top-rated") {
                    add_filter('posts_clauses', array($woocommerce->query, 'order_by_rating_post_clauses'));
                    $args = array('post_type' => 'product', 'post_status' => 'publish', 'product_cat' => $category, 'ignore_sticky_posts' => 1, 'posts_per_page' => $item_count, 'orderby' => $order_by, 'order' => $order);
                    $args['meta_query'] = $woocommerce->query->get_meta_query();
                } else {
                    if ($asset_type == "recently-viewed") {
                        // Get recently viewed product cookies data
                        $viewed_products = !empty($_COOKIE['woocommerce_recently_viewed']) ? (array) explode('|', $_COOKIE['woocommerce_recently_viewed']) : array();
                        $viewed_products = array_filter(array_map('absint', $viewed_products));
                        // If no data, quit
                        if (empty($viewed_products)) {
                            return '<p class="no-products">' . __("You haven't viewed any products yet.", "swiftframework") . '</p>';
                        }
                        // Create query arguments array
                        $args = array('post_type' => 'product', 'post_status' => 'publish', 'product_cat' => $category, 'ignore_sticky_posts' => 1, 'posts_per_page' => $item_count, 'no_found_rows' => 1, 'post__in' => $viewed_products, 'orderby' => $order_by, 'order' => $order);
                        // Add meta_query to query args
                        //$args['meta_query'] = array();
                        // Check products stock status
                        //$args['meta_query'][] = $woocommerce->query->stock_status_meta_query();
                    } else {
                        if ($asset_type == "sale-products") {
                            // Get products on sale
                            $product_ids_on_sale = wc_get_product_ids_on_sale();
                            $meta_query = array();
                            $meta_query[] = WC()->query->visibility_meta_query();
                            $meta_query[] = WC()->query->stock_status_meta_query();
                            $meta_query = array_filter($meta_query);
                            $args = array('product_cat' => $category, 'posts_per_page' => $item_count, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'meta_query' => $meta_query, 'orderby' => $order_by, 'order' => $order, 'post__in' => array_merge(array(0), $product_ids_on_sale));
                        } else {
                            if ($asset_type == "selected-products") {
                                $meta_query = array();
                                $meta_query[] = WC()->query->visibility_meta_query();
                                $meta_query[] = WC()->query->stock_status_meta_query();
                                $meta_query = array_filter($meta_query);
                                $product_ids = explode(',', $products);
                                $args = array('posts_per_page' => -1, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'meta_query' => $meta_query, 'orderby' => $order_by, 'order' => $order, 'post__in' => array_merge(array(0), $product_ids));
                            } else {
                                $args = array('post_type' => 'product', 'post_status' => 'publish', 'product_cat' => $category, 'ignore_sticky_posts' => 1, 'posts_per_page' => $item_count, 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num', 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')));
                                $args['meta_query'] = array();
                                $args['meta_query'][] = $woocommerce->query->stock_status_meta_query();
                                $args['meta_query'][] = $woocommerce->query->visibility_meta_query();
                            }
                        }
                    }
                }
            }
        }
        ob_start();
        // OUTPUT PRODUCTS
        $products = new WP_Query($args);
        // Set Columns
        $woocommerce_loop['columns'] = apply_filters('loop_shop_columns', intval($columns));
        if ($products->have_posts()) {
            ?>
开发者ID:arobbins,项目名称:spellestate,代码行数:66,代码来源:sf-products.php

示例14: sale_products

    /**
     * List all products on sale
     *
     * @param array $atts
     * @return string
     */
    public static function sale_products($atts)
    {
        global $woocommerce_loop;
        $atts = shortcode_atts(array('per_page' => '12', 'columns' => '4', 'orderby' => 'title', 'order' => 'asc'), $atts);
        // Get products on sale
        $product_ids_on_sale = wc_get_product_ids_on_sale();
        $meta_query = WC()->query->get_meta_query();
        $args = array('posts_per_page' => $atts['per_page'], 'orderby' => $atts['orderby'], 'order' => $atts['order'], 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'meta_query' => $meta_query, 'post__in' => array_merge(array(0), $product_ids_on_sale));
        ob_start();
        $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
        $woocommerce_loop['columns'] = $atts['columns'];
        if ($products->have_posts()) {
            ?>

			<?php 
            woocommerce_product_loop_start();
            ?>

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

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

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

			<?php 
            woocommerce_product_loop_end();
            ?>

		<?php 
        }
        wp_reset_postdata();
        return '<div class="woocommerce columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>';
    }
开发者ID:ayoayco,项目名称:upbeat,代码行数:47,代码来源:class-wc-shortcodes.php

示例15: sale_products

 /**
  * List all products on sale.
  *
  * @param array $atts
  * @return string
  */
 public static function sale_products($atts)
 {
     $atts = shortcode_atts(array('per_page' => '12', 'columns' => '4', 'orderby' => 'title', 'order' => 'asc', 'category' => '', 'operator' => 'IN'), $atts);
     $query_args = array('posts_per_page' => $atts['per_page'], 'orderby' => $atts['orderby'], 'order' => $atts['order'], 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'meta_query' => WC()->query->get_meta_query(), 'post__in' => array_merge(array(0), wc_get_product_ids_on_sale()));
     $query_args = self::_maybe_add_category_args($query_args, $atts['category'], $atts['operator']);
     return self::product_loop($query_args, $atts, 'sale_products');
 }
开发者ID:seriusokhatsky,项目名称:woocommerce,代码行数:13,代码来源:class-wc-shortcodes.php


注:本文中的wc_get_product_ids_on_sale函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。