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>'; }
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; }
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(); }
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>'; }
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; }
/** * 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); }
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']); }
/** * 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; }
/** * 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)); }
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>'; }
public function dhvc_woo_products_shortcode($atts, $content = null) { extract(shortcode_atts(array('id' => '', 'heading' => '', 'heading_color' => '#47A3DA', 'heading_font_size' => '20px', 'query_options' => '', 'query_type' => '1', 'products' => '', 'exclude_products' => '', 'category' => '', 'exclude_category' => '', 'brand' => '', 'exclude_brand' => '', 'tag' => '', 'exclude_tag' => '', 'attribute' => '', 'posts_per_page' => '6', 'post_per_row' => '2', 'show' => '', 'orderby' => 'date', 'order' => 'ASC', 'hide_free' => '', 'show_hidden' => '', 'style_options' => '', 'display' => 'grid', 'hide_result_count' => '', 'hide_ordering_list' => '', 'show_grid_pagination' => '', 'show_masonry_filter' => '1', 'masonry_filters_background' => '#ffffff', 'masonry_filters_selected_background' => '#47A3DA', 'masonry_filters_color' => '#666666', 'masonry_filters_selected_color' => '#ffffff', 'masonry_filters_border_color' => '#ffffff', 'masonry_filters_selected_border_color' => '#47A3DA', 'masonry_gutter' => 10, 'hide_carousel_arrows' => '1', 'show_carousel_pagination' => '', 'carousel_arrow_background' => '#CFCDCD', 'carousel_arrow_hover_background' => '#47A3DA', 'carousel_arrow_color' => '#ffffff', 'carousel_arrow_hover_color' => '#ffffff', 'carousel_arrow_size' => '24px', 'carousel_arrow_front_size' => '12px', 'carousel_arrow_border_radius' => '3px', 'carousel_pagination_background' => '#869791', 'carousel_pagination_active_background' => '#47A3DA', 'carousel_pagination_size' => '12px', 'item_border_style' => 'solid', 'item_border_color' => '#e1e1e1', 'item_border_width' => '1px', 'row_separator_color' => '#e1e1e1', 'row_separator_height' => '20px', 'row_separator_border_style' => 'solid', 'hide_thumbnail' => '1', 'thumbnail_background_color' => '#ffffff', 'thumbnail_border_style' => 'solid', 'thumbnail_border_color' => '#e1e1e1', 'thumbnail_border_width' => '1px', 'thumbnail_border_radius' => '3px', 'thumbnail_padding' => '', 'thumbnail_margin' => '', 'thumbnail_width' => '', 'thumbnail_height' => '', 'hide_title' => '1', 'title_align' => 'center', 'title_color' => '#47A3DA', 'title_hover_color' => '#98D2F7', 'title_font_size' => '14px', 'title_padding' => '', 'title_margin' => '', 'show_excerpt' => '', 'excerpt_length' => '15', 'excerpt_align' => '', 'excerpt_color' => '#333333', 'excerpt_font_size' => '12px', 'excerpt_padding' => '', 'excerpt_margin' => '', 'hide_price' => '1', 'price_color' => '#47A3DA', 'no_discount_price_color' => '#333333', 'price_font_size' => '14px', 'no_discount_price_font_size' => '12px', 'price_padding' => '', 'price_margin' => '', 'hide_addtocart' => '1', 'addtocart_text' => 'Add to cart', 'addtocart_color' => '', 'addtocart_font_size' => '14px', 'addtocart_padding' => '', 'addtocart_margin' => '', 'add_cart_price_style' => '2column', 'show_rating' => '1', 'show_sale_flash' => '1', 'el_class' => ''), $atts)); $inline_style = ' #' . $id . ' .dhvc-woo-heading { color:' . $heading_color . '; font-size:' . $heading_font_size . '; } #' . $id . ' .dhvc-woo-item { border: ' . $item_border_width . ' ' . $item_border_style . ' ' . $item_border_color . '; } #' . $id . ' .dhvc-woo-separator{ border-top-color:' . $row_separator_color . '; margin-top:' . absint($row_separator_height) / 2 . 'px; margin-bottom:' . absint($row_separator_height) / 2 . 'px; border-top-style:' . $row_separator_border_style . '; } #' . $id . ' .dhvc-woo-images{ background-color:' . $thumbnail_background_color . '; } #' . $id . ' .dhvc-woo-images img{ border-style:' . $thumbnail_border_style . '; border-width:' . $thumbnail_border_width . '; border-color:' . $thumbnail_border_color . '; border-radius:' . $thumbnail_border_radius . '; -webkit-border-radius:' . $thumbnail_border_radius . '; padding:' . $thumbnail_padding . '; margin:' . $thumbnail_margin . '; } #' . $id . ' .dhvc-woo-title{ text-align:' . $title_align . '; padding:' . $title_padding . '; margin:' . $title_margin . '; } #' . $id . ' .dhvc-woo-title a{ color:' . $title_color . '; font-size:' . $title_font_size . '; } #' . $id . ' .dhvc-woo-title a:hover{ color:' . $title_hover_color . ' } #' . $id . ' .dhvc-woo-excerpt{ text-align:' . $excerpt_align . '; color:' . $excerpt_color . '; font-size:' . $excerpt_font_size . '; padding:' . $excerpt_padding . '; margin:' . $excerpt_margin . '; } #' . $id . ' .dhvc-woo-price{ padding:' . $price_padding . '; margin:' . $price_margin . '; } #' . $id . ' .dhvc-woo-price .amount, #' . $id . ' .dhvc-woo-price ins .amount{ color:' . $price_color . '; font-size:' . $price_font_size . '; } #' . $id . ' .dhvc-woo-price del .amount{ color:' . $no_discount_price_color . '; font-size:' . $no_discount_price_font_size . ' } #' . $id . ' .dhvc-woo-addtocart a{ padding:' . $addtocart_padding . '; margin:' . $addtocart_margin . '; } #' . $id . ' .dhvc-woo-masonry-list .dhvc-woo-masonry-item{ margin-bottom:' . absint($masonry_gutter) . 'px; } #' . $id . ' .dhvc-woo-filters a { border-color:' . $masonry_filters_border_color . '; background-color:' . $masonry_filters_background . '; color:' . $masonry_filters_color . '; } #' . $id . ' .dhvc-woo-filters a.selected, #' . $id . ' .dhvc-woo-filters a:hover{ background-color:' . $masonry_filters_selected_background . '; color:' . $masonry_filters_selected_color . '; border-color:' . $masonry_filters_selected_border_color . '; } #' . $id . ' .dhvc-woo-carousel-arrows a{ background:' . $carousel_arrow_background . '; width:' . $carousel_arrow_size . '; height:' . $carousel_arrow_size . '; border-radius:' . $carousel_arrow_border_radius . '; -webkit-border-radius:' . $carousel_arrow_border_radius . '; } #' . $id . ' .dhvc-woo-carousel-arrows a:hover{ background:' . $carousel_arrow_hover_background . '; } #' . $id . ' .dhvc-woo-carousel-arrows a i{ color:' . $carousel_arrow_color . '; font-size:' . $carousel_arrow_front_size . '; } #' . $id . ' .dhvc-woo-carousel-arrows a:hover i{ color:' . $carousel_arrow_hover_color . '; } #' . $id . ' .owl-controls .owl-page span{ width:' . $carousel_pagination_size . '; height:' . $carousel_pagination_size . '; background:' . $carousel_pagination_background . '; } #' . $id . ' .owl-controls .owl-page.active span, #' . $id . ' .owl-controls.clickable .owl-page:hover span{ background:' . $carousel_pagination_active_background . '; } '; if (defined('YITH_WCWL')) { $label = apply_filters('yith_wcwl_button_label', get_option('yith_wcwl_add_to_wishlist_text')); $br = apply_filters('yith-wcwl-browse-wishlist-label', __('Browse Wishlist', 'yit')); $inline_style .= '#' . $id . ' .dhvc-woo-images .add_to_wishlist:after{ content:"' . $label . '"; } #' . $id . ' .dhvc-woo-images .yith-wcwl-wishlistexistsbrowse a:after, #' . $id . ' .dhvc-woo-images .yith-wcwl-wishlistaddedbrowse a:after{ content:"' . $br . '"; } '; } //wp_enqueue_style('dhvc-woo'); global $woocommerce, $product, $wp_the_query; $posts_per_page = $posts_per_page; $show = sanitize_title($show); $orderby = sanitize_title($orderby); $order = sanitize_title($order); if (is_front_page()) { $paged = get_query_var('page') ? get_query_var('page') : 1; } else { $paged = get_query_var('paged') ? get_query_var('paged') : 1; } $query_args = array('paged' => $paged, 'posts_per_page' => $posts_per_page, 'post_status' => 'publish', 'post_type' => 'product', 'offset' => 0, 'order' => $order == 'asc' ? 'ASC' : 'DESC'); if ($query_type == '1') { if (!empty($products)) { $products_ids = explode(',', $products); $query_args['post__in'] = $products_ids; } if (!empty($exclude_products)) { $exclude_products_ids = explode(',', $exclude_products); $query_args[' post__not_in'] = $exclude_products_ids; } $categories = array(); if (is_product()) { $cat_terms = get_the_terms($product->id, 'product_cat'); if ($cat_terms) { foreach ($cat_terms as $cat) { $categories[] = $cat->term_id; } } } if (!empty($category)) { $category = str_replace('-1', implode(',', $categories), $category); $query_args['tax_query'][] = array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => explode(',', $category), 'operator' => 'IN'); } if (!empty($exclude_category)) { $exclude_category = str_replace('-1', implode(',', $categories), $exclude_category); $query_args['tax_query'][] = array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => explode(',', $exclude_category), 'operator' => 'NOT IN'); } if (!empty($brand)) { $query_args['tax_query'][] = array('taxonomy' => 'product_brand', 'field' => 'id', 'terms' => explode(',', $brand), 'operator' => 'IN'); } if (!empty($exclude_brand)) { $query_args['tax_query'][] = array('taxonomy' => 'product_brand', 'field' => 'id', 'terms' => explode(',', $exclude_brand), 'operator' => 'NOT IN'); } if (!empty($tag)) { $query_args['tax_query'][] = array('taxonomy' => 'product_tag', 'field' => 'id', 'terms' => explode(',', $tag), 'operator' => 'IN'); } if (!empty($exclude_tag)) { $query_args['tax_query'][] = array('taxonomy' => 'product_tag', 'field' => 'id', 'terms' => explode(',', $exclude_tag), 'operator' => 'NOT IN'); } if (!empty($attribute)) { $attribute_arr = explode(',', $attribute); $t = array(); foreach ($attribute_arr as $attr) { $attr_arr = explode('|', $attr); $t[$attr_arr[0]][] = $attr_arr[1]; } if (!empty($t)) { foreach ($t as $key => $tarr) { $query_args['tax_query'][] = array('taxonomy' => $key, 'field' => 'slug', 'terms' => $tarr, 'operator' => 'IN'); } } } } if ($query_type == 'upsell') { $query_args = $this->_get_upsell_product($query_args); if (empty($query_args)) { return; } } 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': $query_args['orderby'] = 'rand'; break; case 'sales': $query_args['meta_key'] = 'total_sales'; $query_args['orderby'] = 'meta_value_num'; break; case 'price': $query_args['meta_key'] = '_price'; $query_args['orderby'] = 'meta_value_num'; $query_args['order'] = 'asc'; break; case 'price-desc': $query_args['meta_key'] = '_price'; $query_args['orderby'] = 'meta_value_num'; $query_args['order'] = 'desc'; break; default: $ordering_args = $woocommerce->query->get_catalog_ordering_args($orderby, $order); $query_args['orderby'] = $ordering_args['orderby']; //$query_args['order'] =$ordering_args['order']; break; } $query_args = apply_filters('dhvc_woo_query_args', $query_args, $atts, $content); $r = new WP_Query($query_args); $output = ''; if (defined('WPB_VC_VERSION') && function_exists('vc_add_param')) { if (!dhvc_is_editor() && !dhvc_is_editor()) { //wp_add_inline_style('dhvc-woo',$inline_style); $output .= '<style type="text/css">' . $inline_style . '</style>'; } else { $output .= '<style type="text/css">' . $inline_style . '</style>'; } } else { //wp_add_inline_style('dhvc-woo',$inline_style); $output .= '<style type="text/css">' . $inline_style . '</style>'; } // wp_enqueue_style('dhvc-woo-font-awesome'); // wp_enqueue_style('dhvc-woo-chosen'); // wp_enqueue_style('dhvc-woo'); $output .= '<div id="' . $id . '" class="woocommerce dhvc-woo ' . $el_class . '">'; if (!empty($heading)) { $output .= '<div class="dhvc-woo-heading">'; $output .= $heading; $output .= '</div>'; } if ($display == 'masonry' && $show_masonry_filter !== '0') { $output .= '<div class="dhvc-woo-filters dhvc-woo-clearfix">'; $output .= '<ul data-option-key="filter">'; $output .= '<li>'; $output .= '<a class="dhvc-woo-filter selected" href="#" data-option-value="*">' . __('All', DHVC_WOO) . '</a>'; $output .= '</li>'; $product_cats = array(); if ($r->have_posts()) { while ($r->have_posts()) { $r->the_post(); global $product; $cats = get_the_terms($product->id, 'product_cat'); if (!empty($cats)) { foreach ($cats as $cat) { $product_cats[$cat->term_id] = $cat->name; } } } foreach ($product_cats as $term_id => $name) { $output .= '<li>'; $output .= '<a href="#" class="dhvc-woo-filter" data-option-value= ".dhvc-woo-cat-' . $term_id . '">' . $name . '</a>'; $output .= '</li>'; } wp_reset_postdata(); wp_reset_query(); } $output .= '</ul>'; $output .= '</div>'; } if ($display == 'carousel' && $hide_carousel_arrows === '0' && $r->post_count > $post_per_row) { $output .= '<div class="dhvc-woo-carousel-arrows dhvc-woo-clearfix">'; $output .= '<a href="#" class="dhvc-woo-carousel-prev"><i class="fa fa-chevron-left"></i></a>'; $output .= '<a href="#" class="dhvc-woo-carousel-next"><i class="fa fa-chevron-right"></i></a>'; $output .= '</div>'; } if ($display != 'carousel' && $display != 'masonry') { if (empty($hide_result_count) || empty($hide_ordering_list)) { $output .= '<div class="dhvc-woo-row-fluid dhvc-woo-toolbar">'; if (empty($hide_result_count)) { ob_start(); dhvc_result_count($r); $output .= ob_get_clean(); } if (empty($hide_ordering_list)) { ob_start(); dhvc_woo_orderby($orderby); $output .= ob_get_clean(); } $output .= '</div>'; } } $output .= '<div class="dhvc-woo-row-fluid dhvc-woo-' . $display . '-list"' . ($display == 'masonry' ? ' data-masonry-gutter="' . absint($masonry_gutter) . '"' : '') . '' . ($display == 'carousel' ? ' data-items="' . absint($post_per_row) . '"' : '') . ($display == 'carousel' && !empty($show_carousel_pagination) ? ' data-pagination="true"' : '') . '>'; if ($r->have_posts()) { $i = 0; while ($r->have_posts()) { $r->the_post(); global $product, $post; $cats = get_the_terms($product->id, 'product_cat'); $product_cats = array(); if (!empty($cats)) { foreach ($cats as $cat) { $product_cats[] = 'dhvc-woo-cat-' . $cat->term_id; } } if ($display == 'grid') { if ($i++ % $post_per_row == 0) { $output .= '<div class="dhvc-woo-row-fluid">'; } } $output .= '<div class="dhvc-woo-item'; if ($display != 'carousel' && $display != 'list') { $output .= ' dhvc-woo-span' . 12 / absint($post_per_row); } $output .= ' dhvc-woo-' . $display . '-item ' . implode(' ', $product_cats); $output .= '">'; $output_image = ''; if ($hide_thumbnail !== '0') { $output_image .= '<div class="dhvc-woo-images">'; if (defined('YITH_WCWL')) { $output_image .= do_shortcode('[yith_wcwl_add_to_wishlist]'); } if ($show_sale_flash !== '0' && $product->is_on_sale()) { ob_start(); woocommerce_show_product_loop_sale_flash(); $output_image .= ob_get_clean(); } if (function_exists('dhwcpl_product_sale')) { ob_start(); dhwcpl_product_sale(); dhwcpl_product_out_of_store(); dhwcpl_shop_loop_item(); $output_image .= ob_get_clean(); } if (has_post_thumbnail()) { $image_title = esc_attr(get_the_title(get_post_thumbnail_id())); $image_link = esc_url(get_permalink()); $thumb_size = 'shop_catalog'; $thumbnail_image = get_the_post_thumbnail($post->ID, 'shop_catalog'); if (!empty($thumbnail_height) && !empty($thumbnail_width)) { $thumb_size = $thumbnail_width . 'x' . $thumbnail_height; $thumbnail_data = dhvc_woo_getImageBySize(array('post_id' => $product->id, 'thumb_size' => $thumb_size)); $thumbnail_image = $thumbnail_data['thumbnail']; } $output_image .= '<a href="' . $image_link . '" itemprop="image" title="' . $image_title . '" >' . $thumbnail_image . '</a>'; } else { $output_image .= apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" title="%s"><img src="%s" alt="Placeholder" /></a>', esc_url(get_permalink()), $image_title, wc_placeholder_img_src()), $product->id); } $output_image .= '</div>'; } $output .= apply_filters('dhvc_woo_images', $output_image, $product, $display); $output .= '<div class="dhvc-woo-info"'; $image_config_size = absint($thumbnail_width); if (empty($image_config_size)) { $shop_single_image_arr = wc_get_image_size('shop_single'); $image_config_size = $shop_single_image_arr['width']; } $image_config_size = $image_config_size + absint($thumbnail_border_width) + absint($thumbnail_border_width); if ($display == 'list') { $output .= 'style="width: calc(100% - ' . $image_config_size . 'px);"'; } $output .= '>'; $output_title = ''; if ($hide_title !== '0') { $output_title .= '<h2 class="dhvc-woo-title dhvc-woo-clearfix">'; $output_title .= '<a href="' . get_permalink() . '">' . the_title('', '', false) . '</a>'; $output_title .= '</h2>'; } $output .= apply_filters('dhvc_woo_title', $output_title, $product, $display); $output_excerpt = ''; if (!empty($show_excerpt)) { $output_excerpt .= '<div class="dhvc-woo-excerpt">'; $output_excerpt .= apply_filters('dhvc-woo-excerpt', wp_trim_words($post->post_excerpt, $excerpt_length), $post); $output_excerpt .= '</div>'; } $output .= apply_filters('dhvc_woo_excerpt', $output_excerpt, $product, $display); $output_rating = ''; if ($show_rating !== '0') { $output_rating .= '<div class="woocommerce dhvc-woo-rating dhvc-woo-clearfix">'; $rating = $product->get_average_rating(); $rating = absint($rating); $rating_html = '<div class="star-rating" title="' . sprintf(__('Rated %s out of 5', 'woocommerce'), $rating) . '">'; $rating_html .= '<span style="width:' . $rating / 5 * 100 . '%"><strong class="rating">' . $rating . '</strong> ' . __('out of 5', 'woocommerce') . '</span>'; $rating_html .= '</div>'; $output_rating .= $rating_html; $output_rating .= '</div>'; } $output .= apply_filters('dhvc_woo_rating', $output_rating, $product, $display); $output .= '<div class="dhvc-woo-extra dhvc-woo-row-fluid">'; if ($display == 'list') { $output_price = ''; if ($hide_price !== '0') { $output_price .= '<div class="dhvc-woo-price">'; $output_price .= $product->get_price_html(); $output_price .= '</div>'; } $output .= apply_filters('dhvc_woo_price', $output_price, $product, $display); $output_addtocart = ''; if ($hide_addtocart !== '0') { $output_addtocart .= '<div class="dhvc-woo-addtocart">'; ob_start(); wc_get_template('loop/add-to-cart.php'); $add_to_cart = ob_get_clean(); $output_addtocart .= apply_filters('dhvc-woo-add-to-cart', $add_to_cart, $product); $output_addtocart .= '</div>'; } $output .= apply_filters('dhvc_woo_addtocart', $output_addtocart, $product, $display); } else { //'add_cart_price_style'=>'2column', if ($add_cart_price_style == '1column') { $output_price = ''; if ($hide_price !== '0') { $output_price .= '<div class="dhvc-woo-price dhvc-woo-span12">'; $output_price .= $product->get_price_html(); $output_price .= '</div>'; } $output .= apply_filters('dhvc_woo_price', $output_price, $product, $display); $output_addtocart = ''; if ($hide_addtocart !== '0') { $output_addtocart .= '<div class="dhvc-woo-addtocart dhvc-woo-span12">'; ob_start(); wc_get_template('loop/add-to-cart.php'); $add_to_cart = ob_get_clean(); $output_addtocart .= apply_filters('dhvc-woo-add-to-cart', $add_to_cart, $product); $output_addtocart .= '</div>'; } $output .= apply_filters('dhvc_woo_addtocart', $output_addtocart, $product, $display); } else { $output_addtocart = ''; if ($hide_addtocart !== '0') { $output_addtocart .= '<div class="dhvc-woo-addtocart dhvc-woo-span6">'; ob_start(); wc_get_template('loop/add-to-cart.php'); $add_to_cart = ob_get_clean(); $output_addtocart .= apply_filters('dhvc-woo-add-to-cart', $add_to_cart, $product); $output_addtocart .= '</div>'; } $output .= apply_filters('dhvc_woo_addtocart', $output_addtocart, $product, $display); $output_price = ''; if ($hide_price !== '0') { $output_price .= '<div class="dhvc-woo-price dhvc-woo-span6">'; $output_price .= $product->get_price_html(); $output_price .= '</div>'; } $output .= apply_filters('dhvc_woo_price', $output_price, $product, $display); } } $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; if ($display == 'grid') { if ($i % $post_per_row == 0 || $i == $r->post_count) { $output .= '</div>'; $output .= '<div class="dhvc-woo-separator"></div>'; } } } } $output .= '</div>'; if (!empty($show_grid_pagination) && $display != 'carousel' && $display != 'masonry') { $pagination = dhvc_woo_pagination(array('echo' => false), $r); $output .= $pagination; } $output .= '</div>'; wp_reset_postdata(); wp_reset_query(); return $output; }
/** * 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); }
function sf_product_items($atts) { extract(shortcode_atts(array('title' => '', 'asset_type' => '', 'category' => '', 'products' => '', 'display_layout' => '', 'display_type' => '', 'carousel' => '', 'multi_masonry' => '', 'fullwidth' => '', 'gutters' => '', 'columns' => '', 'item_count' => '', 'order_by' => '', 'order' => '', 'button_enabled' => '', 'width' => ''), $atts)); global $woocommerce, $woocommerce_loop, $sf_sidebar_config, $sf_carouselID, $sf_options, $sf_product_multimasonry, $sf_product_display_layout; if ($sf_carouselID == "") { $sf_carouselID = 1; } else { $sf_carouselID++; } if (is_singular('portfolio')) { $sf_sidebar_config = "no-sidebars"; } $list_class = ""; $product_display_type = $sf_options['product_display_type']; if ($display_type != "") { $product_display_type = $display_type; } if ($fullwidth == "yes") { $list_class .= 'products-full-width '; } if ($gutters == "no" || $product_display_type == "gallery-bordered") { $list_class .= 'no-gutters '; } if ($multi_masonry == "yes" && $product_display_type != "preview-slider" && $asset_type != "categories") { $carousel = "no"; $list_class .= 'multi-masonry-items '; $sf_product_multimasonry = true; } else { $sf_product_multimasonry = false; } if ($display_layout != '') { $sf_product_display_layout = $display_layout; } if ($carousel == "no" && $multi_masonry == "no") { $list_class .= 'product-grid '; } $list_class .= 'product-type-' . $product_display_type . ' '; $woocommerce_loop['style-override'] = $product_display_type; $args = array(); $sf_prev_icon = apply_filters('sf_carousel_prev_icon', '<i class="ss-navigateleft"></i>'); $sf_next_icon = apply_filters('sf_carousel_next_icon', '<i class="ss-navigateright"></i>'); // CATEGORY ASSET OUTPUT if ($asset_type == "categories") { ob_start(); $hide_empty = 1; $category_id = ''; $ids = array(); if ($category != "") { $category = str_replace("0,", "", $category); $categories = explode(',', $category); foreach ($categories as $term) { $category_term = get_term_by('slug', $term, 'product_cat'); $category_id = $category_term->term_id; array_push($ids, $category_id); } } $args = array('hide_empty' => $hide_empty, 'pad_counts' => true, 'include' => $ids); $product_categories = get_terms('product_cat', $args); if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($item_count) { $product_categories = array_slice($product_categories, 0, $item_count); } ob_start(); if ($product_categories) { if ($carousel == "yes") { ?> <div class="product-carousel carousel-wrap <?php echo $list_class; ?> "> <ul class="products list-<?php echo $asset_type; ?> carousel-items gutters" id="carousel-<?php echo $sf_carouselID; ?> " data-columns="<?php echo $columns; ?> "> <?php foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } ?> </ul> <?php if (sf_theme_opts_name() != "sf_atelier_options") { ?> <a href="#" class="carousel-prev"><?php echo $sf_prev_icon; ?> </a> <a href="#" class="carousel-next"><?php echo $sf_next_icon; ?> </a> <?php } ?> </div> <?php } else { ?> <ul class="products list-<?php echo $asset_type; ?> row <?php echo $list_class; ?> "> <?php foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } ?> </ul> <?php } } woocommerce_reset_loop(); $product_list_output = ob_get_contents(); ob_end_clean(); wp_reset_query(); wp_reset_postdata(); return $product_list_output; } // 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()) { ?> <?php if ($carousel == "yes") { ?> <div class="product-carousel carousel-wrap <?php echo $list_class; ?> "> <ul class="products list-<?php echo $asset_type; ?> carousel-items gutters" id="carousel-<?php echo $sf_carouselID; ?> " data-columns="<?php echo $columns; ?> "> <?php while ($products->have_posts()) { $products->the_post(); ?> <?php woocommerce_get_template_part('content', 'product'); ?> <?php } // end of the loop. ?> </ul> <?php if (sf_theme_opts_name() != "sf_atelier_options" && sf_theme_opts_name() != "sf_uplift_options") { ?> <a href="#" class="carousel-prev"><?php echo $sf_prev_icon; ?> </a> <a href="#" class="carousel-next"><?php echo $sf_next_icon; ?> </a> <?php } ?> </div> <?php } else { ?> <ul class="products list-<?php echo $asset_type; ?> row <?php echo $list_class; ?> " data-columns="<?php echo $columns; ?> "> <?php if ($multi_masonry == "yes") { ?> <div class="clearfix product col-sm-3 grid-sizer"></div> <?php } ?> <?php while ($products->have_posts()) { $products->the_post(); ?> <?php woocommerce_get_template_part('content', 'product'); ?> <?php } // end of the loop. ?> </ul> <?php } ?> <?php } // Get contents and then clean output $product_list_output = ob_get_contents(); ob_end_clean(); // Reset query wp_reset_query(); wp_reset_postdata(); remove_filter('posts_clauses', array($woocommerce->query, 'order_by_rating_post_clauses')); // Reset global $sf_product_display_layout = ""; return $product_list_output; }
/** * 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>'; }
/** * 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'); }
/** * @deprecated */ function woocommerce_get_product_ids_on_sale() { return wc_get_product_ids_on_sale(); }
/** * @param $query */ public function pre_get_posts($query) { // store original meta_query $meta_query = $query->get('meta_query'); if (isset($_GET['filter'])) { $filter = $_GET['filter']; // barcode // todo: allow users to set custom meta field if (isset($filter['barcode'])) { $meta_query[] = array('key' => '_sku', 'value' => $filter['barcode'], 'compare' => 'LIKE'); } // featured // todo: more general meta_key test using $query_args_whitelist if (isset($filter['featured'])) { $meta_query[] = array('key' => '_featured', 'value' => $filter['featured'] ? 'yes' : 'no', 'compare' => '='); } // on sale // - no easy way to get on_sale items // - wc_get_product_ids_on_sale uses cached data, includes variations if (isset($filter['on_sale'])) { $sale_ids = array_filter(wc_get_product_ids_on_sale()); $exclude = isset($query->query['post__not_in']) ? $query->query['post__not_in'] : array(); $ids = array_diff($sale_ids, $exclude); $query->set('post__not_in', array()); $query->set('post__in', $ids); } } // update the meta_query $query->set('meta_query', $meta_query); }
public function get_products($args, $instance) { $number_display = !empty($instance['number_display']) ? absint($instance['number_display']) : 4; $show = !empty($instance['show']) ? sanitize_title($instance['show']) : 'recent'; global $woocommerce; $args = array('post_type' => 'product', 'posts_per_page' => $number_display, 'post_status' => 'publish'); switch ($show) { case 'best_selling': $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; $args['ignore_sticky_posts'] = 1; $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); break; case 'featured_product': $args['ignore_sticky_posts'] = 1; $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes'); $query_args['meta_query'][] = $woocommerce->query->visibility_meta_query(); break; case 'top_rate': add_filter('posts_clauses', array($woocommerce->query, 'order_by_rating_post_clauses')); $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); break; case 'recent': $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); break; case 'on_sale': $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); $args['post__in'] = wc_get_product_ids_on_sale(); break; case 'recent_review': if ($post_per_page == -1) { $_limit = 4; } else { $_limit = $post_per_page; } global $wpdb; $query = $wpdb->prepare("\n\t\t\t\t\tSELECT c.comment_post_ID\n\t\t\t\t\tFROM {$wpdb->prefix}posts p, {$wpdb->prefix}comments c\n\t\t\t\t\tWHERE p.ID = c.comment_post_ID AND c.comment_approved > %d\n\t\t\t\t\tAND p.post_type = %s AND p.post_status = %s\n\t\t\t\t\tAND p.comment_count > %d ORDER BY c.comment_date ASC", 0, 'product', 'publish', 0); $results = $wpdb->get_results($query, OBJECT); $_pids = array(); foreach ($results as $re) { if (!in_array($re->comment_post_ID, $_pids)) { $_pids[] = $re->comment_post_ID; } if (count($_pids) == $_limit) { break; } } $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); $args['post__in'] = $_pids; break; } return new WP_Query($args); }
/** * Inherit coupon validity from parent: * * - Coupon is invalid for bundled item if parent is excluded. * - Coupon is valid for bundled item if valid for parent, unless bundled item is excluded. * * @param bool $valid * @param WC_Product $product * @param WC_Coupon $coupon * @param array $cart_item * @return bool */ public function wc_cp_coupon_validity($valid, $product, $coupon, $cart_item) { if (!empty(WC()->cart)) { $cart_contents = WC()->cart->cart_contents; if (!empty($cart_item['composite_parent']) && !empty($cart_item['composite_item'])) { $composite_cart_key = $cart_item['composite_parent']; if (isset($cart_contents[$composite_cart_key])) { $composite = $cart_contents[$composite_cart_key]['data']; $composite_id = $composite->id; if (apply_filters('woocommerce_composite_inherit_coupon_validity', true, $product, $coupon, $cart_item, $cart_contents[$composite_cart_key])) { if ($valid) { $parent_excluded = false; // Parent ID excluded from the discount. if (sizeof($coupon->exclude_product_ids) > 0) { if (in_array($composite_id, $coupon->exclude_product_ids)) { $parent_excluded = true; } } // Parent category excluded from the discount. if (sizeof($coupon->exclude_product_categories) > 0) { $product_cats = WC_CP_Core_Compatibility::wc_get_product_cat_ids($composite_id); if (sizeof(array_intersect($product_cats, $coupon->exclude_product_categories)) > 0) { $parent_excluded = true; } } // Sale Items excluded from discount and parent on sale. if ($coupon->exclude_sale_items == 'yes') { $product_ids_on_sale = wc_get_product_ids_on_sale(); if (in_array($composite_id, $product_ids_on_sale, true)) { $parent_excluded = true; } } if ($parent_excluded) { $valid = false; } } else { $bundled_product_excluded = false; // Bundled product ID excluded from the discount. if (sizeof($coupon->exclude_product_ids) > 0) { if (in_array($product->id, $coupon->exclude_product_ids) || isset($product->variation_id) && in_array($product->variation_id, $coupon->exclude_product_ids) || in_array($product->get_parent(), $coupon->exclude_product_ids)) { $bundled_product_excluded = true; } } // Bundled product category excluded from the discount. if (sizeof($coupon->exclude_product_categories) > 0) { $product_cats = WC_CP_Core_Compatibility::wc_get_product_cat_ids($product->id); if (sizeof(array_intersect($product_cats, $coupon->exclude_product_categories)) > 0) { $bundled_product_excluded = true; } } // Bundled product on sale and sale items excluded from discount. if ($coupon->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)) { $bundled_product_excluded = true; } } elseif (in_array($product->id, $product_ids_on_sale, true)) { $bundled_product_excluded = true; } } if (!$bundled_product_excluded && $coupon->is_valid_for_product($composite, $cart_contents[$composite_cart_key])) { $valid = true; } } } } } } return $valid; }
protected function content($atts, $content = null) { $atts = function_exists('vc_map_get_attributes') ? vc_map_get_attributes('hot_deal', $atts) : $atts; extract(shortcode_atts(array('title' => 'Tabs Name', 'per_page' => 5, 'taxonomy' => 0, 'orderby' => 'date', 'order' => 'DESC', 'style' => 'style-1', 'autoplay' => 'false', 'navigation' => 'false', 'loop' => 'false', 'slidespeed' => 250, 'margin' => 0, 'css' => '', 'el_class' => '', 'nav' => 'true', 'items_destop' => 4, 'items_tablet' => 3, 'items_mobile' => 1, 'use_responsive' => 1, 'css_animation' => ''), $atts)); global $woocommerce_loop; $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, ' box-tab-category ', $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)); $meta_query = WC()->query->get_meta_query(); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'suppress_filter' => true, 'orderby' => $orderby, 'order' => $order); if ($taxonomy) { $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => explode(",", $taxonomy))); } $product_ids_on_sale = wc_get_product_ids_on_sale(); $args['post__in'] = array_merge(array(0), $product_ids_on_sale); $data_carousel = array("autoplay" => $autoplay, "navigation" => $navigation, "margin" => $margin, "slidespeed" => $slidespeed, "theme" => 'style-navigation-bottom', "autoheight" => 'false', 'nav' => 'true', 'dots' => 'false', 'loop' => $loop, 'autoplayTimeout' => 1000, 'autoplayHoverPause' => 'true'); if ($use_responsive) { $arr = array('0' => array("items" => $items_mobile), '768' => array("items" => $items_tablet), '992' => array("items" => $items_destop)); $data_responsive = json_encode($arr); $data_carousel["responsive"] = $data_responsive; } else { if ($items_destop > 0) { $items_destop = 4; } $data_carousel['items'] = $items_destop; } $carousel = _data_carousel($data_carousel); $tabs = kt_get_all_attributes('tab_sections', $content); if (count($tabs) > 0) { $unique = uniqid(); $new_title = array(__('hot'), __('deals')); $charact = explode(' ', $title); if (is_array($charact) && count($charact) > 1) { $new_title = $charact; } ?> <?php ob_start(); ?> <div class="<?php if ($style == "style-1") { ?> option3 <?php } else { ?> option4 <?php } ?> "> <!-- Hot deals --> <div class="hot-deals-row container-tab"> <div class="hot-deals-box only_countdown"> <div class="row"> <div class="col-sm-12 col-md-12 col-lg-4"> <div class="hot-deals-tab"> <div class="hot-deals-title vertical-text"> <?php if (isset($new_title[0]) && $new_title[0]) { ?> <?php for ($i = 0; $i < strlen($new_title[0]); $i++) { ?> <?php if (isset($new_title[0][$i])) { ?> <span><?php echo esc_html($new_title[0][$i]); ?> </span> <?php } ?> <?php } ?> <?php } ?> <?php for ($j = 1; $j < count($new_title); $j++) { ?> <?php if (isset($new_title[$j]) && $new_title[$j]) { ?> <?php for ($i = 0; $i < strlen($new_title[$j]); $i++) { ?> <?php if (isset($new_title[$j][$i])) { ?> <span class="yellow"><?php echo esc_html($new_title[$j][$i]); ?> </span> <?php } ?> <?php } ?> <?php } ?> <?php } ?> </div> <div class="hot-deals-tab-box"> <ul class="nav-tab"> <?php $i = 1; ?> <?php foreach ($tabs as $tab) { extract(shortcode_atts(array('header' => __('Tab name', 'kutetheme'), 'reduction_from' => 0, 'reduction_to' => 0), $tab)); ?> <li <?php if ($i == 1) { ?> class="active" <?php } ?> ><a data-toggle="tab" href="#hotdeals-<?php echo $unique; ?> -<?php echo $i; ?> "><?php echo $header; ?> </a></li> <?php $i++; ?> <?php } ?> </ul> <div class="box-count-down"> <span class="countdown-only"></span> </div> </div> </div> </div> <div class="col-sm-12 col-md-12 col-lg-8 hot-deals-tab-content-col"> <div class="hot-deals-tab-content tab-container"> <?php $i = 1; ?> <?php $max_time = 0; foreach ($tabs as $tab) { extract(shortcode_atts(array('header' => __('Tab name', 'kutetheme'), 'reduction_from' => 0, 'reduction_to' => 0), $tab)); $meta = $meta_query; $meta[] = array('key' => '_reduction_percent', 'value' => array($reduction_from, $reduction_to), 'compare' => 'BETWEEN'); $args['meta_query'] = $meta; $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts)); if ($products->have_posts()) { 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); remove_action('kt_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 10); ?> <div id="hotdeals-<?php echo $unique; ?> -<?php echo $i; ?> " class="tab-panel <?php if ($i == 1) { ?> active<?php } ?> "> <?php do_action("woocommerce_shortcode_before_hot_deal_loop"); ?> <ul class="product-list owl-carousel nav-center" <?php echo $carousel; ?> > <?php while ($products->have_posts()) { $products->the_post(); ?> <li> <?php wc_get_template_part('content', 'product-hot-deal'); // Get date sale $time = kt_get_max_date_sale(get_the_ID()); if ($time > $max_time) { $max_time = $time; } ?> </li> <?php } ?> </ul> <?php do_action("woocommerce_shortcode_after_hot_deal_loop"); ?> </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); add_action('kt_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 10); ?> <?php } else { ?> <div id="hotdeals-<?php echo $unique; ?> -<?php echo $i; ?> " class="tab-panel <?php if ($i == 1) { ?> active<?php } ?> "> <label><?php _e('Empty product', 'kutetheme'); ?> </label> </div> <?php } ?> <?php wp_reset_query(); wp_reset_postdata(); ?> <?php $i++; ?> <?php } ?> <?php if ($max_time > 0) { $y = date('Y', $max_time); $m = date('m', $max_time); $d = date('d', $max_time); ?> <input class="max-time-sale" data-y="<?php echo esc_attr($y); ?> " data-m="<?php echo esc_attr($m); ?> " data-d="<?php echo esc_attr($d); ?> " type="hidden" value="" /> <?php } ?> </div> </div> </div> </div> </div> </div> <!-- ./Hot deals --> <?php } $result = ob_get_contents(); ob_end_clean(); return $result; }
protected function content($atts, $content = null) { $atts = function_exists('vc_map_get_attributes') ? vc_map_get_attributes('tab_producs', $atts) : $atts; $atts = shortcode_atts(array('taxonomy' => '', 'style' => '1', 'per_page' => 12, 'columns' => 4, 'border_heading' => '', 'css_animation' => '', 'el_class' => '', 'css' => '', 'autoplay' => 'false', 'navigation' => 'false', 'margin' => 30, 'slidespeed' => 200, 'css' => '', 'el_class' => '', 'nav' => 'true', 'loop' => 'false', 'use_responsive' => 1, 'items_destop' => 3, 'items_tablet' => 2, 'items_mobile' => 1), $atts); extract($atts); global $woocommerce_loop; $is_phone = false; if (function_exists('kt_is_phone') && kt_is_phone()) { $is_phone = true; } if ($style == 3) { $base_class = 'tab-product-13 option-13 style1 '; } else { $base_class = 'popular-tabs '; } $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $base_class, $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_product_tab_class_container', $elementClass); $tabs = array('best-sellers' => __('Best Sellers', 'edo'), 'on-sales' => __('On Sales', 'edo'), 'new-arrivals' => __('New Products', 'edo')); $meta_query = WC()->query->get_meta_query(); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'meta_query' => $meta_query, 'suppress_filter' => true); if ($taxonomy) { $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => explode(",", $taxonomy))); } $uniqeID = uniqid(); ob_start(); ?> <div class="<?php echo esc_attr($elementClass); ?> top-nav container-tab style<?php echo esc_attr($style); ?> "> <ul class="nav-tab"> <?php $i = 0; ?> <?php foreach ($tabs as $k => $v) { ?> <li <?php echo $i == 0 ? 'class="active"' : ''; ?> > <a data-toggle="tab" href="#tab-<?php echo esc_attr($k) . $uniqeID; ?> "><?php echo esc_html($v); ?> </a> </li> <?php $i++; ?> <?php } ?> </ul> <div class="tab-container"> <?php $data_carousel = array("autoplay" => $autoplay, "navigation" => $navigation, "margin" => $margin, "slidespeed" => $slidespeed, "theme" => 'style-navigation-bottom', "autoheight" => 'false', 'nav' => $navigation, 'dots' => 'false', 'loop' => $loop, 'autoplayTimeout' => 1000, 'autoplayHoverPause' => 'true'); if ($use_responsive) { $arr = array('0' => array("items" => $items_mobile), '768' => array("items" => $items_tablet), '992' => array("items" => $items_destop)); $data_responsive = json_encode($arr); $data_carousel["responsive"] = $data_responsive; } else { if ($style == 3) { $data_carousel['items'] = 4; } else { $data_carousel['items'] = 3; } } $carousel = _data_carousel($data_carousel); $i = 0; ?> <?php foreach ($tabs as $k => $v) { ?> <?php $newargs = $args; if ($k == 'best-sellers') { $newargs['meta_key'] = 'total_sales'; $newargs['orderby'] = 'meta_value_num'; } elseif ($k == 'on-sales') { $product_ids_on_sale = wc_get_product_ids_on_sale(); $newargs['post__in'] = array_merge(array(0), $product_ids_on_sale); $newargs['orderby'] = 'date'; $newargs['order'] = 'DESC'; } else { $newargs['orderby'] = 'date'; $newargs['order'] = 'DESC'; } $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $newargs, $atts)); if ($products->have_posts()) { ?> <!-- Style 1 --> <?php if ($style == 1) { ?> <div id="tab-<?php echo esc_attr($k) . $uniqeID; ?> " class="tab-panel <?php echo $i == 0 ? 'active' : ''; ?> "> <ul class="products kt-owl-carousel" <?php echo apply_filters('kt_shortcode_tab_product_carousel', $carousel); ?> > <?php while ($products->have_posts()) { $products->the_post(); ?> <li class="product style6 no-hiden"> <?php wc_get_template_part('content', 'product-tab'); ?> </li> <?php } ?> </ul> </div> <!-- ./Style 1 --> <?php } ?> <?php } ?> <?php wp_reset_query(); wp_reset_postdata(); $i++; ?> <?php } ?> </div> </div> <?php return ob_get_clean(); }
public function products($atts, $contents) { self::$int++; $int = self::$int; if (!class_exists('WooCommerce')) { return false; } $atts = shortcode_atts(array('title' => '', 'product_layout' => '', 'product_banner' => '', 'product_banner_align' => 'center', 'product_group' => 'products_categories', 'product_cat_ids' => '', 'product_ids' => '', 'product_skus' => '', 'product_orderby' => 'date', 'product_order' => 'DESC', 'after_content' => '', 'before_content' => '', 'max_items' => '10', 'img_size' => 'shop_catalog_image_size', 'el_class' => '', 'css' => '', 'width' => '1/3', 'offset' => ''), $atts); // Add Class $width = $css = ''; $width = wpb_translateColumnWidthToSpan($atts['width']); $width = vc_column_offset_class_merge($atts['offset'], $width); $__width = array(); $__width = explode(' ', $width); $parent_class = array(); $item_class = array(); if (is_array($__width)) { foreach ($__width as $__class) { if (strpos($__class, 'hidden') > 0) { $parent_class[] = $__class; } else { $item_class[] = $__class; } } //$width = implode($item_class, ' '); } $parent_class[] = vc_shortcode_custom_css_class($atts['css']); $parent_class[] = $atts['product_styles']; $parent_class[] = 'woocommerce'; if (!empty($atts['el_class'])) { $parent_class[] = $atts['el_class']; } $layout = ''; if ($atts['product_layout'] == 'tab') { $parent_class[] = 'mTheme-products-tab'; } else { $layout = $atts['product_layout']; } $columns = m_wedding_translateColumnWidthVC($atts['width']); //$css_classes = array( //'wpb_column', //'vc_column_container', //$width //); // Query $args = array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $atts['max_items']); if ($atts['product_group'] == 'recent_products') { $args = array_merge($args, array('ignore_sticky_posts' => 1, 'orderby' => $atts['product_orderby'], 'order' => $atts['product_order'], 'meta_query' => WC()->query->get_meta_query())); } elseif ($atts['product_group'] == 'featured_products') { $meta_query = WC()->query->get_meta_query(); $meta_query[] = array('key' => '_featured', 'value' => 'yes'); $args = array_merge($args, array('ignore_sticky_posts' => 1, 'orderby' => $atts['product_orderby'], 'order' => $atts['product_order'], 'meta_query' => $meta_query)); } elseif ($atts['product_group'] == 'sale_products') { $args = array_merge($args, array('no_found_rows' => 1, 'orderby' => $atts['product_orderby'], 'order' => $atts['product_order'], 'meta_query' => WC()->query->get_meta_query(), 'post__in' => array_merge(array(0), wc_get_product_ids_on_sale()))); } elseif ($atts['product_group'] == 'best_selling_products') { $args = array_merge($args, array('ignore_sticky_posts' => 1, 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num', 'meta_query' => WC()->query->get_meta_query())); } elseif ($atts['product_group'] == 'top_rated_products') { $args = array_merge($args, array('ignore_sticky_posts' => 1, 'orderby' => $atts['product_orderby'], 'order' => $atts['product_order'], 'meta_query' => WC()->query->get_meta_query())); add_filter('posts_clauses', array('WC_Shortcodes', 'order_by_rating_post_clauses')); } elseif ($atts['product_group'] == 'products_categories') { if (isset($atts['product_cat_ids'])) { $term_ids = explode(',', $atts['product_cat_ids']); $term_ids = array_map('trim', $term_ids); } else { $term_ids = array(); } $args = array_merge($args, array('ignore_sticky_posts' => 1, 'orderby' => $atts['product_orderby'], 'order' => $atts['product_order'], 'meta_query' => WC()->query->get_meta_query(), 'tax_query' => array(array('taxonomy' => 'product_cat', 'terms' => $term_ids, 'field' => 'term_id')))); } else { $post__in = ''; if (!empty($atts['product_ids'])) { $post__in = array_map('trim', explode(',', $atts['product_ids'])); } $args = array_merge($args, array('ignore_sticky_posts' => 1, 'meta_query' => WC()->query->get_meta_query(), 'post__in' => $post__in)); if (!empty($atts['product_skus'])) { $args['meta_query'][] = array('key' => '_sku', 'value' => array_map('trim', explode(',', $atts['product_skus'])), 'compare' => 'IN'); } } $query = new WP_Query($args); ob_start(); echo '<div id="mtheme-products-' . $int . '" class="mtheme-products ' . join($parent_class, ' ') . '">'; if (!empty($atts['title']) || !empty($atts['before_content'])) { echo '<div class="mtheme-title">'; if (!empty($atts['title'])) { echo wpb_widget_title(array('title' => $atts['title'], 'extraclass' => 'wpb_singleimage_heading')); } if (!empty($atts['before_content'])) { echo '<div class="before-content">' . $atts['before_content'] . '</div>'; } echo '</div>'; } echo '<div class="mtheme-products-inner">'; $template = self::mTheme_get_template_part('content-products', $layout); if (file_exists("{$template}")) { if ($query->have_posts()) { require "{$template}"; } else { echo __('Not empty', 'mTheme'); } } echo '</div>'; if (!empty($contents)) { echo '<div class="after-content">' . $contents . '</div>'; } echo "</div>"; if ($atts['product_group'] == 'top_rated_products') { remove_filter('posts_clauses', array('WC_Shortcodes', 'order_by_rating_post_clauses')); } wp_reset_postdata(); return ob_get_clean(); }
function wpo_woocommerce_query($type, $post_per_page = -1, $cat = '') { global $woocommerce; $args = array('post_type' => 'product', 'posts_per_page' => $post_per_page, 'post_status' => 'publish'); switch ($type) { case 'best_selling': $args['meta_key'] = 'total_sales'; $args['orderby'] = 'meta_value_num'; $args['ignore_sticky_posts'] = 1; $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); break; case 'featured_product': $args['ignore_sticky_posts'] = 1; $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes'); $query_args['meta_query'][] = $woocommerce->query->visibility_meta_query(); break; case 'top_rate': add_filter('posts_clauses', array($woocommerce->query, 'order_by_rating_post_clauses')); $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); break; case 'recent_product': $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); break; case 'on_sale': $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); $args['post__in'] = wc_get_product_ids_on_sale(); break; case 'recent_review': if ($post_per_page == -1) { $_limit = 4; } else { $_limit = $post_per_page; } global $wpdb; $query = "SELECT c.comment_post_ID FROM {$wpdb->prefix}posts p, {$wpdb->prefix}comments c WHERE p.ID = c.comment_post_ID AND c.comment_approved > 0 AND p.post_type = 'product' AND p.post_status = 'publish' AND p.comment_count > 0 ORDER BY c.comment_date ASC"; $results = $wpdb->get_results($query, OBJECT); $_pids = array(); foreach ($results as $re) { if (!in_array($re->comment_post_ID, $_pids)) { $_pids[] = $re->comment_post_ID; } if (count($_pids) == $_limit) { break; } } $args['meta_query'] = array(); $args['meta_query'][] = $woocommerce->query->stock_status_meta_query(); $args['meta_query'][] = $woocommerce->query->visibility_meta_query(); $args['post__in'] = $_pids; break; } if ($cat != '') { $args['product_cat'] = $cat; } return new WP_Query($args); }
protected function content($atts, $content = null) { $atts = function_exists('vc_map_get_attributes') ? vc_map_get_attributes('box_products', $atts) : $atts; extract(shortcode_atts(array('title' => __('hot deals', 'kutetheme'), 'per_page' => 5, 'type' => 'hot-deals', 'taxonomy' => 0, 'orderby' => 'date', 'order' => 'DESC', 'main_color' => '#ff3300', 'style' => 'style-1', 'banner' => '', 'banner_link' => '', 'speed_banner' => '250', 'autoplay' => 'false', 'navigation' => 'false', 'margin' => 20, 'slidespeed' => 250, 'nav' => 'true', 'loop' => 'true', 'use_responsive' => 1, 'items_destop' => 4, 'items_tablet' => 2, 'items_mobile' => 1, 'css' => '', 'css_animation' => '', 'el_class' => ''), $atts)); global $woocommerce_loop; $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'box-products ', $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)); if (function_exists('kt_hex2rgb')) { $main_color_rgb = kt_hex2rgb($main_color); } else { $main_color_rgb = array('red' => 255, 'green' => 51, 'blue' => 102); } ob_start(); $meta_query = WC()->query->get_meta_query(); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'suppress_filter' => true, 'meta_query' => $meta_query); if ($type == 'hot-deals') { $product_ids_on_sale = wc_get_product_ids_on_sale(); $args['post__in'] = array_merge(array(0), $product_ids_on_sale); if ($orderby == 'discount') { $newargs['meta_key'] = '_reduction_percent'; $newargs['orderby'] = 'meta_value_num'; } else { $args['orderby'] = $orderby; } $args['order'] = $order; if (!$title) { $title = __('Hot Deals', 'kutetheme'); } } elseif ($type == 'best-selling') { $newargs['meta_key'] = 'total_sales'; $newargs['orderby'] = 'meta_value_num'; if (!$title) { $title = __('Best Selling', 'kutetheme'); } } elseif ($type == 'recent-product') { $args['orderby'] = $orderby; $args['order'] = $order; if (!$title) { $title = __('New Arrivals', 'kutetheme'); } } elseif ($type == 'most-review') { add_filter('posts_clauses', array($this, 'order_by_rating_post_clauses')); if (!$title) { $title = __('Most Reviews', 'kutetheme'); } } $cate_ids = array(); if ($taxonomy) { $cate_ids = explode(",", $taxonomy); $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $cate_ids)); } $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts)); if ($products->have_posts()) { $data_carousel = array("autoplay" => $autoplay, "navigation" => $navigation, "margin" => $margin, "slidespeed" => $slidespeed, "theme" => 'style-navigation-top', "autoheight" => 'false', 'nav' => 'true', 'dots' => 'false', 'loop' => $loop, 'autoplayTimeout' => 1000, 'autoplayHoverPause' => 'true'); if ($use_responsive) { $arr = array('0' => array("items" => $items_mobile), '768' => array("items" => $items_tablet), '992' => array("items" => $items_destop)); $data_responsive = json_encode($arr); $data_carousel["responsive"] = $data_responsive; } else { $data_carousel['items'] = $items_destop; } $unique_id = uniqid(); $carousel = _data_carousel($data_carousel); $banner_i = 1; if (isset($banner) && $banner) { $banner_args = array('post_type' => 'attachment', 'include' => $banner, 'orderby' => 'post__in'); $list_banner = get_posts($banner_args); ob_start(); foreach ($list_banner as $l) { ?> <li> <a target="_blank" href="<?php echo $banner_link ? esc_url($banner_link) : ''; ?> "> <?php echo wp_get_attachment_image($l->ID, 'full'); ?> </a> </li> <?php $banner_i++; } $banner_carousel = ob_get_clean(); } 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); remove_action('kt_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 10); ?> <div class="container-tab <?php if ($style == "style-1") { ?> option3 <?php } else { ?> option4 <?php } ?> "> <!-- box product --> <div class="<?php echo apply_filters('kt_class_box_product', $elementClass); ?> " id="change-color-<?php echo esc_attr($unique_id); ?> " data-target="change-color" data-color="<?php echo esc_attr($main_color); ?> " data-rgb="<?php echo esc_attr(implode(',', $main_color_rgb)); ?> "> <div class="box-product-head"> <span class="box-title"><?php echo esc_html($title); ?> </span> <ul class="box-tabs nav-tab"> <li class="active"> <a data-toggle="tab" href="#tab-all-<?php echo $unique_id; ?> "> <?php _e('All', 'edo'); ?> </a> </li> <?php if (count($cate_ids)) { ?> <?php foreach ($cate_ids as $id) { ?> <?php $term = get_term($id, 'product_cat'); $cate_obj[] = $term; ?> <li> <a data-toggle="tab" href="#tab-<?php echo esc_attr($term->term_id . '-' . $unique_id); ?> "> <?php echo esc_html($term->name); ?> </a> </li> <?php } ?> <?php } ?> </ul> </div> <div class="box-product-content"> <?php if (isset($banner_carousel)) { ?> <div class="box-product-adv"> <ul class="owl-carousel nav-center" data-slidespeed="<?php echo intval($speed_banner); ?> " data-items="1" data-dots="false" <?php if ($banner_i > 2) { ?> data-autoplay="true" data-loop="true" <?php } else { ?> data-autoplay="false" data-loop="false" <?php } ?> data-nav="true"> <?php echo apply_filters('kt_banner_box_product', $banner_carousel); ?> </ul> </div> <?php } ?> <div class="box-product-list" <?php if (!isset($banner_carousel)) { ?> style="margin-left: 0;" <?php } ?> > <div class="tab-container"> <div id="tab-all-<?php echo esc_attr($unique_id); ?> " class="tab-panel active"> <?php do_action("woocommerce_shortcode_before_box_product_loop"); ?> <?php $this->kt_loop_product($products, $carousel); ?> <?php do_action("woocommerce_shortcode_after_box_product_loop"); ?> </div> <?php if (count($cate_obj) > 0) { ?> <?php foreach ($cate_obj as $term) { $args['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $term->term_id)); $term_products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts)); if ($term_products->have_posts()) { ?> <div id="tab-<?php echo $term->term_id . '-' . $unique_id; ?> " class="tab-panel"> <?php do_action("woocommerce_shortcode_before_box_product_loop"); ?> <?php $this->kt_loop_product($term_products, $carousel); ?> <?php do_action("woocommerce_shortcode_after_box_product_loop"); ?> </div> <?php } else { ?> <div id="tab-<?php echo $term->term_id . '-' . $unique_id; ?> " class="tab-panel"> <?php $this->kt_tab_empty(); ?> </div> <?php } ?> <?php } ?> <?php } ?> </div> </div> </div> </div> <!-- ./box product --> </div> <?php add_action('kt_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 10); 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); if ($type == 'most-review') { remove_filter('posts_clauses', array($this, 'order_by_rating_post_clauses')); } } return ob_get_clean(); }
$args['tax_query'] = array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $term->term_id, 'operator' => 'IN')); } $i = 0; ?> <?php foreach ($tabs as $tab) { $tab = function_exists('vc_map_get_attributes') ? vc_map_get_attributes('tab_section', $tab) : $atts; extract(shortcode_atts(array('header' => 'Section Name', 'section_type' => 'best-seller', 'section_cate' => 0, 'orderby' => 'date', 'order' => 'DESC', 'ids' => ''), $tab)); $ids = explode(',', $ids); $key = isset($tab['section_type']) ? $tab['section_type'] : 'best-seller'; $newargs = $args; if ($key == 'new-arrival') { $newargs['orderby'] = 'date'; $newargs['order'] = 'DESC'; } elseif ($key == 'on-sales') { $product_ids_on_sale = wc_get_product_ids_on_sale(); $newargs['post__in'] = array_merge(array(0), $product_ids_on_sale); if ($orderby == '_sale_price') { $orderby = 'date'; $order = 'DESC'; } $newargs['orderby'] = $orderby; $newargs['order'] = $order; } elseif ($key == 'custom') { if ($orderby == '_sale_price') { $newargs['meta_query'] = array('relation' => 'OR', array('key' => '_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric'), array('key' => '_min_variation_sale_price', 'value' => 0, 'compare' => '>', 'type' => 'numeric')); } else { $newargs['orderby'] = $orderby; $newargs['order'] = $order; } } elseif ($key == 'most-review') {
/** * Query args. * * @param array $args Request args. * @param WP_REST_Request $request Request data. * @return array */ public function query_args($args, $request) { // Set post_status. $args['post_status'] = $request['status']; // Taxonomy query to filter products by type, category, // tag, shipping class, and attribute. $tax_query = array(); // Map between taxonomy name and arg's key. $taxonomies = array('product_cat' => 'category', 'product_tag' => 'tag', 'product_shipping_class' => 'shipping_class'); // Set tax_query for each passed arg. foreach ($taxonomies as $taxonomy => $key) { if (!empty($request[$key])) { $tax_query[] = array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $request[$key]); } } // Filter product type by slug. if (!empty($request['type'])) { $tax_query[] = array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $request['type']); } // Filter by attribute and term. if (!empty($request['attribute']) && !empty($request['attribute_term'])) { if (in_array($request['attribute'], wc_get_attribute_taxonomy_names(), true)) { $tax_query[] = array('taxonomy' => $request['attribute'], 'field' => 'term_id', 'terms' => $request['attribute_term']); } } if (!empty($tax_query)) { $args['tax_query'] = $tax_query; } // Filter featured. if (is_bool($request['featured'])) { $args['tax_query'][] = array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured'); } // Filter by sku. if (!empty($request['sku'])) { $args['meta_query'] = $this->add_meta_query($args, array('key' => '_sku', 'value' => $request['sku'])); } // Filter by tax class. if (!empty($request['tax_class'])) { $args['meta_query'] = $this->add_meta_query($args, array('key' => '_tax_class', 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '')); } // Price filter. if (!empty($request['min_price']) || !empty($request['max_price'])) { $args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); } // Filter product in stock or out of stock. if (is_bool($request['in_stock'])) { $args['meta_query'] = $this->add_meta_query($args, array('key' => '_stock_status', 'value' => true === $request['in_stock'] ? 'instock' : 'outofstock')); } // Filter by on sale products. if (is_bool($request['on_sale'])) { $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; $args[$on_sale_key] += wc_get_product_ids_on_sale(); } // Apply all WP_Query filters again. if (is_array($request['filter'])) { $args = array_merge($args, $request['filter']); unset($args['filter']); } // Force the post_type argument, since it's not a user input variable. if (!empty($request['sku'])) { $args['post_type'] = array('product', 'product_variation'); } else { $args['post_type'] = $this->post_type; } return $args; }
/** * function to validate smart coupon for product * * @param bool $valid * @param WC_Product|null $product * @param WC_Coupon|null $coupon * @param array|null $values * @return bool $valid */ public function smart_coupons_is_valid_for_product($valid, $product = null, $coupon = null, $values = null) { if (empty($product) || empty($coupon)) { return $valid; } if ($coupon->discount_type == 'smart_coupon') { $product_cats = wp_get_post_terms($product->id, 'product_cat', array("fields" => "ids")); // Specific products get the discount if (sizeof($coupon->product_ids) > 0) { if (in_array($product->id, $coupon->product_ids) || isset($product->variation_id) && in_array($product->variation_id, $coupon->product_ids) || in_array($product->get_parent(), $coupon->product_ids)) { $valid = true; } // Category discounts } elseif (sizeof($coupon->product_categories) > 0) { if (sizeof(array_intersect($product_cats, $coupon->product_categories)) > 0) { $valid = true; } } else { // No product ids - all items discounted $valid = true; } // Specific product ID's excluded from the discount if (sizeof($coupon->exclude_product_ids) > 0) { if (in_array($product->id, $coupon->exclude_product_ids) || isset($product->variation_id) && in_array($product->variation_id, $coupon->exclude_product_ids) || in_array($product->get_parent(), $coupon->exclude_product_ids)) { $valid = false; } } // Specific categories excluded from the discount if (sizeof($coupon->exclude_product_categories) > 0) { if (sizeof(array_intersect($product_cats, $coupon->exclude_product_categories)) > 0) { $valid = false; } } // Sale Items excluded from discount if ($coupon->exclude_sale_items == 'yes') { $product_ids_on_sale = wc_get_product_ids_on_sale(); if (in_array($product->id, $product_ids_on_sale, true) || isset($product->variation_id) && in_array($product->variation_id, $product_ids_on_sale, true) || in_array($product->get_parent(), $product_ids_on_sale, true)) { $valid = false; } } } return $valid; }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ public function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $number = absint($instance['number']); $show = sanitize_title($instance['show']); $orderby = sanitize_title($instance['orderby']); $order = sanitize_title($instance['order']); $show_rating = false; $query_args = array('posts_per_page' => $number, 'post_status' => 'publish', 'post_type' => 'product', 'no_found_rows' => 1, 'order' => $order == 'asc' ? 'asc' : 'desc'); $query_args['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'; } $r = new WP_Query($query_args); if ($r->have_posts()) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="product_list_widget">'; while ($r->have_posts()) { $r->the_post(); wc_get_template('content-widget-product.php', array('show_rating' => $show_rating)); } echo '</ul>'; echo $after_widget; } wp_reset_postdata(); $content = ob_get_clean(); echo $content; $this->cache_widget($args, $content); }
/** * Check if a coupon is valid for a product * * @param WC_Product $product * @return boolean */ public function is_valid_for_product($product) { if ($this->type != 'fixed_product' && $this->type != 'percent_product') { return apply_filters('woocommerce_coupon_is_valid_for_product', false, $product, $this); } $valid = false; $product_cats = wp_get_post_terms($product->id, 'product_cat', array("fields" => "ids")); // 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 } elseif (sizeof($this->product_categories) > 0) { if (sizeof(array_intersect($product_cats, $this->product_categories)) > 0) { $valid = true; } } else { // 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 (in_array($product->id, $product_ids_on_sale, true) || isset($product->variation_id) && in_array($product->variation_id, $product_ids_on_sale, true) || in_array($product->get_parent(), $product_ids_on_sale, true)) { $valid = false; } } return apply_filters('woocommerce_coupon_is_valid_for_product', $valid, $product, $this); }
/** * Get products on-sale * * Shown on homepage * * @param type $per_page * @param type $paged * @return \WP_Query */ function dokan_get_on_sale_products($per_page = 10, $paged = 1) { // Get products on sale $product_ids_on_sale = wc_get_product_ids_on_sale(); $args = array('posts_per_page' => $per_page, 'no_found_rows' => 1, 'paged' => $paged, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => array_merge(array(0), $product_ids_on_sale), 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_stock_status', 'value' => 'instock', 'compare' => '='))); return new WP_Query(apply_filters('dokan_on_sale_products_query', $args)); }