function wb_products($atts, $before, $after) { global $woocommerce_loop; $atts = shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => '', 'ids' => ''), $atts); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_categories = get_terms('product_cat', $args); if ('' !== $atts['parent']) { $product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($atts['number']) { $product_categories = array_slice($product_categories, 0, $atts['number']); } $columns = absint($atts['columns']); $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { echo $before; foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } echo $after; } woocommerce_reset_loop(); return ob_get_clean(); }
/** * List all (or limited) product categories * * @param array $atts * @return string */ public static function product_categories($atts) { global $woocommerce_loop; $atts = shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'product_tag' => '', 'parent' => '', 'ids' => ''), $atts); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent'], 'product_tag' => $atts['product_tag']); $product_categories = get_terms('product_cat', $args); $product_tags = get_terms('product_tag', $args); if ('' !== $atts['parent']) { $product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent'])); } foreach ($product_tags as $key => $category) { if ($category->slug == $atts['product_tag']) { // echo "<script>console.log( 'Debug Objects: " .json_encode($category) . "' );</script>"; } } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($atts['number']) { $product_categories = array_slice($product_categories, 0, $atts['number']); } $woocommerce_loop['columns'] = $atts['columns']; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { woocommerce_product_loop_start(); foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); echo "<script>console.log( 'Debug Objects: " . json_encode($category) . "' );</script>"; } woocommerce_product_loop_end(); } woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>'; }
public function product_lookbook_shortcode($atts, $content = null) { global $woocommerce_loop; $atts = shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => '', 'ids' => ''), $atts); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_brands = get_terms('product_brand', $args); if ('' !== $atts['parent']) { $product_brands = wp_list_filter($product_brands, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_brands as $key => $brand) { if ($brand->count == 0) { unset($product_brands[$key]); } } } if ($atts['number']) { $product_brands = array_slice($product_brands, 0, $atts['number']); } $woocommerce_loop['columns'] = $atts['columns']; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_brands) { woocommerce_product_loop_start(); foreach ($product_brands as $brand) { wc_get_template('content-product_brand.php', array('brand' => $brand)); } woocommerce_product_loop_end(); } woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>'; }
/** * List all (or limited) product categories. * * @param array $atts * @return string */ public static function product_categories($atts) { global $woocommerce_loop; $atts = shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => '', 'ids' => ''), $atts); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $atts['parent']); $product_categories = get_terms('product_cat', $args); if ('' !== $atts['parent']) { $product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent'])); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($atts['number']) { $product_categories = array_slice($product_categories, 0, $atts['number']); } $columns = absint($atts['columns']); $woocommerce_loop['columns'] = $columns; ob_start(); if ($product_categories) { woocommerce_product_loop_start(); foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } woocommerce_product_loop_end(); } woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }
function mr_tailor_product_categories_einhornified($atts) { extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'parent' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } ob_start(); $cat_counter = 0; $cat_number = count($product_categories); if ($product_categories) { foreach ($product_categories as $category) { $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true); $image = wp_get_attachment_url($thumbnail_id); $cat_class = ""; $cat_counter++; switch ($cat_number) { case 1: $cat_class = "one_cat_" . $cat_counter; break; case 2: $cat_class = "two_cat_" . $cat_counter; break; case 3: $cat_class = "three_cat_" . $cat_counter; break; case 4: $cat_class = "four_cat_" . $cat_counter; break; case 5: $cat_class = "five_cat_" . $cat_counter; break; default: if ($cat_counter < 7) { $cat_class = $cat_counter; } else { $cat_class = "more_than_6"; } } ?> <div class="category_<?php echo $cat_class; ?> "> <div class="category_grid_box"> <span class="category_item_bkg" style="background-image:url(<?php echo $image; ?> )"></span> <a href="<?php echo get_term_link($category->slug, 'product_cat'); ?> " class="category_item" > <span class="category_name"><?php // echo $category->name; ?> </span> </a> </div> </div> <?php } ?> <div class="clearfix"></div> <?php } woocommerce_reset_loop(); return '<div class="row"><div class="categories_grid test">' . ob_get_clean() . '</div></div>'; }
function etheme_product_categories($atts) { global $woocommerce_loop; extract(shortcode_atts(array('number' => null, 'title' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'parent' => '', 'display_type' => 'grid', 'class' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $title_output = ''; if ($title != '') { $title_output = '<h3 class="title"><span>' . $title . '</span></h3>'; } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } //$woocommerce_loop['columns'] = $columns; if ($display_type == 'slider') { $class .= 'owl-carousel carousel-area'; } else { $class .= 'row'; } $box_id = rand(1000, 10000); ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; $woocommerce_loop['display_type'] = $display_type; if ($product_categories) { if ($display_type == 'menu') { $instance = array('title' => $title, 'hierarchical' => 1, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $args = array(); the_widget('WC_Widget_Product_Categories', $instance, $args); } else { echo $title_output; echo '<div class="categoriesCarousel ' . $class . ' slider-' . $box_id . '">'; foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } echo '</div>'; } if ($display_type == 'slider') { echo ' <script type="text/javascript"> jQuery(".slider-' . $box_id . '").owlCarousel({ items:4, lazyLoad : true, navigation: true, navigationText:false, rewindNav: false, itemsCustom: [[0, 1], [479,2], [619,3], [768,3], [1200, 4], [1600, 4]] }); </script> '; } } woocommerce_reset_loop(); return ob_get_clean(); }
function ux_product_categories_grid($atts, $content = null) { extract(shortcode_atts(array('number' => 9999, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'parent' => '', 'height' => '600px', 'grid' => '1', 'padding' => '15px', 'offset' => '', 'bg_overlay' => '#000'), $atts)); $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'pad_counts' => true, 'child_of' => $parent, 'offset' => $offset); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $bannergridID = rand(); $tall_height = $height; $less_tall_height = $height - $height / 3 - $padding / 2 . 'px'; $small_height = $height / 2 - $padding / 2 . 'px'; $smallest_height = $height / 3 - $padding / 1.5 . 'px'; $g_total = '0'; if ($grid == '1') { $g_total = '5'; $g = array('height1' => $tall_height, 'span1' => 'large-6 small-12', 'height2' => $tall_height, 'span2' => 'large-3 small-6', 'height3' => $small_height, 'span3' => 'large-3 small-6', 'height4' => $small_height, 'span4' => 'large-3 small-6', 'height5' => $small_height, 'span5' => 'large-3 small-6'); } if ($grid == '2') { $g_total = '4'; $g = array('height1' => $tall_height, 'span1' => 'large-12 small-12', 'height2' => $smallest_height, 'span2' => 'large-4 small-12', 'height3' => $smallest_height, 'span3' => 'large-4 small-12', 'height4' => $smallest_height, 'span4' => 'large-4 small-12'); } if ($grid == '3') { $g_total = '3'; $g = array('height1' => $tall_height, 'span1' => 'large-6 small-12', 'height2' => $small_height, 'span2' => 'large-6 small-6', 'height3' => $small_height, 'span3' => 'large-3 small-6'); } if ($grid == '4') { $g_total = '1'; $g = array('height1' => $tall_height, 'span1' => 'large-3 small-6'); } if ($grid == '5') { $g_total = '1'; $g = array('height1' => $tall_height, 'span1' => 'large-4 small-6'); } if ($grid == '6') { $g_total = '4'; $g = array('height1' => $tall_height, 'span1' => 'large-8 small-12', 'height2' => $small_height, 'span2' => 'large-4 small-6', 'height3' => $small_height, 'span3' => 'large-4 small-6', 'height4' => $small_height, 'span4' => 'large-4 small-6'); } if ($grid == '7') { $g_total = '4'; $g = array('height1' => $tall_height, 'span1' => 'large-3 small-6', 'height2' => $tall_height, 'span2' => 'large-6 small-12', 'height3' => $small_height, 'span3' => 'large-3 small-6', 'height4' => $small_height, 'span4' => 'large-3 small-6'); } if ($grid == '8') { $g_total = '4'; $g = array('height1' => $tall_height, 'span1' => 'large-3 small-6', 'height2' => $tall_height, 'span2' => 'large-6 small-12', 'height3' => $tall_height, 'span3' => 'large-3 small-6', 'height4' => $small_height, 'span4' => 'large-3 small-6'); } if ($grid == '9') { $g_total = '2'; $g = array('height1' => $tall_height, 'span1' => 'large-6 small-12', 'height2' => $small_height, 'span2' => 'large-3 small-6'); } if ($grid == '10') { $g_total = '5'; $g = array('height1' => $tall_height, 'span1' => 'large-6 small-12', 'height2' => $smallest_height, 'span2' => 'large-6 small-12', 'height3' => $smallest_height, 'span3' => 'large-3 small-12', 'height4' => $smallest_height, 'span4' => 'large-3 small-12', 'height5' => $smallest_height, 'span5' => 'large-6 small-12'); } if ($grid == '11') { $g_total = '5'; $g = array('height1' => $less_tall_height, 'span1' => 'large-6 small-12', 'height2' => $less_tall_height, 'span2' => 'large-3 small-12', 'height3' => $tall_height, 'span3' => 'large-3 small-12', 'height4' => $smallest_height, 'span4' => 'large-3 small-12', 'height5' => $smallest_height, 'span5' => 'large-6 small-12'); } if ($grid == '12') { $g_total = '6'; $g = array('height1' => $smallest_height, 'span1' => 'large-8 small-12', 'height2' => $smallest_height, 'span2' => 'large-4 small-12', 'height3' => $smallest_height, 'span3' => 'large-4 small-12', 'height4' => $smallest_height, 'span4' => 'large-8 small-12', 'height5' => $smallest_height, 'span5' => 'large-8 small-12', 'height6' => $smallest_height, 'span6' => 'large-4 small-12'); } if ($grid == '13') { $g_total = '6'; $g = array('height1' => $less_tall_height, 'span1' => 'large-6 small-12', 'height2' => $small_height, 'span2' => 'large-3 small-12', 'height3' => $tall_height, 'span3' => 'large-3 small-12', 'height4' => $smallest_height, 'span4' => 'large-6 small-12', 'height5' => $small_height, 'span5' => 'large-3 small-12', 'height6' => $smallest_height, 'span6' => 'large-6 small-12'); } if ($grid == '14') { $g_total = '6'; $g = array('height1' => $smallest_height, 'span1' => 'large-9 small-12', 'height2' => $tall_height, 'span2' => 'large-3 small-12', 'height3' => $less_tall_height, 'span3' => 'large-3 small-12', 'height4' => $smallest_height, 'span4' => 'large-3 small-12', 'height5' => $smallest_height, 'span5' => 'large-3 small-12', 'height6' => $smallest_height, 'span6' => 'large-6 small-12'); } ob_start(); ?> <?php if ($padding) { $padding_w = $padding / 2; ?> <style> #banner_grid_<?php echo $bannergridID; ?> .ux_banner-grid{margin-left: -<?php echo $padding_w; ?> px !important; margin-right: -<?php echo $padding_w; ?> px !important;} #banner_grid_<?php echo $bannergridID; ?> .ux_banner-grid .columns{margin-bottom: <?php echo $padding; ?> !important} #banner_grid_<?php echo $bannergridID; ?> .ux_banner-grid .columns > .column-inner{padding-left: <?php echo $padding_w; ?> px !important; padding-right: <?php echo $padding_w; ?> px !important;} </style> <?php } ?> <div id="banner_grid_<?php echo $bannergridID; ?> "> <div class="row"> <div class="large-12 columns"> <div class="row collapse ux_banner-grid ux_banner-grid-new"> <?php /** * Check if WooCommerce is active **/ if (function_exists('wc_print_notices')) { ?> <?php if ($product_categories) { foreach ($product_categories as $category) { global $woocommerce_loop; // Store loop count we're currently on if (empty($woocommerce_loop['loop'])) { $woocommerce_loop['loop'] = 0; } // Increase loop count $woocommerce_loop['loop']++; if ($woocommerce_loop['loop'] < $g_total) { $cat_span = $g['span' . $woocommerce_loop['loop']]; $cat_height = $g['height' . $woocommerce_loop['loop']]; } else { $cat_span = $g['span' . $g_total]; $cat_height = $g['height' . $g_total]; } $idcat = $category->woocommerce_term_id; $thumbnail_id = get_woocommerce_term_meta($idcat, 'thumbnail_id', true); $image = wp_get_attachment_image_src($thumbnail_id, 'large'); $image = $image[0]; if ($category->count > 0) { $cat_count = apply_filters('woocommerce_subcategory_count_html', ' <span class="count">' . $category->count . ' ' . __('Products', 'woocommerce') . '</span>', $category); } $cat_link = get_term_link($category->slug, 'product_cat'); ?> <div class="columns ux-grid-column <?php echo $cat_span; ?> " style="height:<?php echo $cat_height; ?> "> <div class="column-inner cat-banner"> <?php echo fixShortcode(' [ux_banner bg_overlay="' . $bg_overlay . '" link="' . $cat_link . '" hover="fade" text_color="light" bg="' . $image . '" tx_color="dark" animate="none" tx_width="60%"] <h2 class="uppercase cat-title">' . $category->name . '</h2><p class="cat-count hide-for-small lead uppercase">' . $cat_count . '</p> [/ux_banner]'); ?> </div><!-- .column-inner --> </div><!-- .columns --> <?php } } woocommerce_reset_loop(); ?> <?php } ?> </div> </div> </div> <script> jQuery(document).ready(function ($) { var $container = $("#banner_grid_<?php echo $bannergridID; ?> .ux_banner-grid"); $container.packery({ itemSelector: ".columns", gutter: 0 }); }); </script> </div><!-- #grid --> <?php $content = ob_get_contents(); ob_end_clean(); return $content; }
/** * List all (or limited) product categories * * @access public * @param array $atts * @return string */ public static function product_categories($atts) { global $woocommerce_loop; extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { woocommerce_product_loop_start(); foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } woocommerce_product_loop_end(); } woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }
function vc_woo_carousel_product_category_func($atts, $content = null) { extract(shortcode_atts(array('per_page' => '12', 'columns' => '', 'orderby' => '', 'order' => '', 'category' => '', 'operator' => 'IN', 'carousel_autoheight' => '', 'carousel_margin' => '', 'carousel_navi' => '', 'carousel_dots_navi' => '', 'carousel_autoplay' => '', 'carousel_autoplaytimeout' => '', 'carousel_autoplayhoverpause' => '', 'carousel_loop' => ''), $atts)); if (empty($columns)) { $columns = '2'; } if (empty($orderby)) { $orderby = 'date'; } if (empty($order)) { $order = 'DESC'; } global $woocommerce_loop; if (!$category) { return ''; } // Default ordering args $ordering_args = WC()->query->get_catalog_ordering_args($orderby, $order); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $ordering_args['orderby'], 'order' => $ordering_args['order'], 'posts_per_page' => $per_page, 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')), 'tax_query' => array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => $operator))); if (isset($ordering_args['meta_key'])) { $args['meta_key'] = $ordering_args['meta_key']; } global $shortcode_atts; $shortcode_atts = array('carousel_autoheight' => $carousel_autoheight, 'carousel_margin' => $carousel_margin, 'carousel_navi' => $carousel_navi, 'carousel_dots_navi' => $carousel_dots_navi, 'carousel_autoplay' => $carousel_autoplay, 'carousel_autoplaytimeout' => $carousel_autoplaytimeout, 'carousel_autoplayhoverpause' => $carousel_autoplayhoverpause, 'carousel_loop' => $carousel_loop, 'columns' => $columns); lpd_owl_carousel(); global $carousel_product_category_ID; $carousel_product_category_ID = rand(); ob_start(); ?> <?php $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts)); $woocommerce_loop['columns'] = $columns; if ($products->have_posts()) { ?> <div class="row"> <ul class="lpd-products owl-carousel-<?php echo esc_attr($carousel_product_category_ID); ?> "> <?php while ($products->have_posts()) { $products->the_post(); ?> <?php wc_get_template_part('content', 'product'); ?> <?php } // end of the loop. ?> </ul></div> <?php } ?> <?php $counter_js = new carousel_product_category_class(); $counter_js->carousel_product_category_callback(); ?> <?php woocommerce_reset_loop(); wp_reset_postdata(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }
protected function content($atts, $content = null) { $atts = shortcode_atts(array('text' => '', 'subtitle' => '', 'backend' => '', 'align' => 'center', 'layout' => '1', 'font_container' => '', 'use_theme_fonts' => 'yes', 'google_fonts' => '', 'font_container_subtitle' => '', 'font_container_backend' => '', 'source' => 'widgets', 'categories' => '', 'per_page' => 8, 'products_layout' => 'grid', 'columns' => 4, 'orderby' => 'date', 'order' => 'DESC', 'hover_effect' => '', 'active_section' => 1, 'css_animation' => '', 'el_class' => '', 'css' => '', 'nav' => '1', 'operator' => 'IN', 'product_columns' => '4', 'product_columns_desktop' => '3', 'product_columns_tablet' => '2'), $atts); if ($atts['products_layout'] == 'carousel') { $atts['columns'] = $atts['product_columns']; } extract($atts); $elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'wc-products-tab', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'align' => 'wc-products-' . $align); $heading = ''; if ($text) { $elementClassHeading = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'kt-heading ', $this->settings['base'], $atts), 'align' => 'text-' . $align, 'layout' => 'style' . $layout); $heading = $style_title_css = $style_backend_css = $style_subtitle_css = ''; $style_title = $this->getCustomStyle($atts); if (!empty($style_title['style'])) { $style_title_css = 'style="' . esc_attr(implode(';', $style_title['style'])) . '"'; } $heading_title = '<' . $style_title['data']['values']['tag'] . ' class="kt-heading-title" ' . $style_title_css . ' >' . $text . '</' . $style_title['data']['values']['tag'] . '>'; $heading_subtitle = ''; if ($subtitle) { $atts['font_container'] = $atts['font_container_subtitle']; $atts['google_fonts'] = ''; $style_subtitle = $this->getCustomStyle($atts); if (!empty($style_subtitle['style'])) { $style_subtitle_css = 'style="' . esc_attr(implode(';', $style_subtitle['style'])) . '"'; } $heading_subtitle = '<div class="kt-heading-subtitle" ' . $style_subtitle_css . '>' . $subtitle . '</div>'; } $heading_backend = ''; if ($backend) { $atts['font_container'] = $atts['font_container_backend']; $atts['google_fonts'] = ''; $style_backend = $this->getCustomStyle($atts); if (!empty($style_backend['style'])) { $style_backend_css = 'style="' . esc_attr(implode(';', $style_backend['style'])) . '"'; } $heading_backend = '<div class="kt-heading-backend" ' . $style_backend_css . '>' . $backend . '</div>'; } $heading .= $heading_backend . $heading_title . $heading_subtitle; $elementClassHeading = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClassHeading)); $heading = '<div class="' . esc_attr($elementClassHeading) . '">' . $heading . '</div>'; } $uniqeID = uniqid(); $meta_query = WC()->query->get_meta_query(); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $atts['per_page'], 'meta_query' => $meta_query); $tabs = array(); if ($source == 'categories') { $tabs = explode(',', $categories); $args['order'] = $order; $args['orderby'] = $orderby; } else { $tabs = array('featured', 'new', 'bestselling'); } $tab_heading = '<ul class="nav nav-style-' . $nav . '" data-count="' . count($tabs) . '">'; $i = 1; foreach ($tabs as $tab) { if ($source == 'categories') { $term = get_term_by('slug', sanitize_title($tab), 'product_cat'); $text = $term->name; } else { if ($tab == 'featured') { $text = esc_html__('Hot Products', 'wingman'); } elseif ($tab == 'new') { $text = esc_html__('New Arrivals', 'wingman'); } elseif ($tab == 'bestselling') { $text = esc_html__('Best Sellers', 'wingman'); } } $class = $active_section == $i ? ' class="active"' : ''; $tab_heading .= sprintf('<li %s><a href="%s" data-toggle="tab"><span data-hover="%s">%s</span></a></li>', $class, '#tab-' . $tab . '-' . $uniqeID, esc_attr($text), $text); $i++; } $tab_heading .= "</ul>"; global $woocommerce_loop; $i = 1; $output_content = ''; foreach ($tabs as $tab) { $new_args = $args; if ($source == 'categories') { $new_args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => sanitize_title($tab), 'field' => 'slug', 'operator' => $atts['operator'])); } else { if ($tab == 'bestselling') { $new_args['meta_key'] = 'total_sales'; $new_args['orderby'] = 'meta_value_num'; } elseif ($tab == 'featured') { $new_args['meta_query'][] = array('key' => '_featured', 'value' => 'yes'); } } $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $new_args, $atts)); $woocommerce_loop['columns'] = $atts['columns']; $woocommerce_loop['effect'] = $atts['hover_effect']; ob_start(); if ($products->have_posts()) { if ($products_layout == 'carousel') { echo sprintf('<div class="owl-carousel-kt"><div class="wc-carousel-wrapper" data-options=\'{"desktop": "%s","desktopsmall": "%s","tablet": "%s","mobile": "1","navigation": true, "pagination": false}\'>', $product_columns, $product_columns_desktop, $product_columns_tablet); } 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(); if ($products_layout == 'carousel') { echo '</div></div>'; } } woocommerce_reset_loop(); wp_reset_postdata(); $class = $active_section == $i ? 'fade in active' : ''; $output_content .= sprintf('<div id="%s" class="tab-pane %s">%s</div><!-- .tab-pane -->', 'tab-' . $tab . '-' . $uniqeID, $class, ob_get_clean()); $i++; } $output = sprintf('<div class="wc-products-tab-heading">%s</div><div class="tab-content">%s</div>', $heading . $tab_heading, $output_content); $elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass)); $output = '<div class="' . esc_attr($elementClass) . '"><div class="woocommerce columns-' . $atts['columns'] . '">' . $output . '</div></div>'; return $output; }
function vc_woo_carousel_product_categories_func($atts, $content = null) { extract(shortcode_atts(array('number' => null, 'orderby' => '', 'order' => '', 'columns' => '', 'hide_empty' => '', 'parent' => '', 'carousel_autoheight' => '', 'carousel_margin' => '', 'carousel_navi' => '', 'carousel_dots_navi' => '', 'carousel_autoplay' => '', 'carousel_autoplaytimeout' => '', 'carousel_autoplayhoverpause' => '', 'carousel_loop' => ''), $atts)); if (empty($columns)) { $columns = '2'; } if (empty($orderby)) { $orderby = 'date'; } if (empty($order)) { $order = 'DESC'; } if (empty($hide_empty)) { $hide_empty = '1'; } global $woocommerce_loop; if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $woocommerce_loop['columns'] = $columns; global $shortcode_atts; $shortcode_atts = array('carousel_autoheight' => $carousel_autoheight, 'carousel_margin' => $carousel_margin, 'carousel_navi' => $carousel_navi, 'carousel_dots_navi' => $carousel_dots_navi, 'carousel_autoplay' => $carousel_autoplay, 'carousel_autoplaytimeout' => $carousel_autoplaytimeout, 'carousel_autoplayhoverpause' => $carousel_autoplayhoverpause, 'carousel_loop' => $carousel_loop, 'columns' => $columns); lpd_owl_carousel(); global $carousel_product_categories_ID; $carousel_product_categories_ID = rand(); ob_start(); ?> <?php // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { ?> <div class="row"><ul class="lpd-products owl-carousel-<?php echo esc_attr($carousel_product_categories_ID); ?> "> <?php foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } ?> </ul></div> <?php } $counter_js = new carousel_product_categories_class(); $counter_js->carousel_product_categories_callback(); woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }
function thb_grid($atts, $content = null) { extract(shortcode_atts(array('type' => 'categories', 'style' => 'style1', 'cat' => '', 'product_ids' => '', 'animation' => 'animation fade-in'), $atts)); global $woocommerce, $woocommerce_loop, $product, $post; $args = $product_categories = $category_ids = array(); $cats = explode(",", $cat); foreach ($cats as $cat) { $c = get_term_by('slug', $cat, 'product_cat'); if ($c) { array_push($category_ids, $c->term_id); } } $args = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => '0', 'include' => $category_ids); $product_categories = get_terms('product_cat', $args); ob_start(); $i = 1; ?> <?php if ($type == "categories") { ?> <?php if ($product_categories) { ?> <div class="grid"> <?php foreach ($product_categories as $category) { if ($style == "style1") { switch ($i) { case 1: case 6: case 11: case 16: $imagesize = array("1440", "800"); $articlesize = 'small-12 medium-8'; break; case 2: case 7: case 12: case 17: $imagesize = array("720", "406"); $articlesize = 'small-12 medium-4 grid-sizer'; break; case 4: case 5: case 9: case 10: case 14: case 15: $imagesize = array("720", "400"); $articlesize = 'small-12 medium-4'; break; case 3: case 8: case 13: case 18: $imagesize = array("720", "800"); $articlesize = 'small-12 medium-4'; break; } } else { if ($style == "style2") { switch ($i) { case 1: case 13: $imagesize = array("720", "798"); $articlesize = 'small-12 medium-6'; break; case 2: case 4: case 5: case 6: case 9: case 8: case 10: case 11: case 14: case 15: $imagesize = array("360", "400"); $articlesize = 'small-12 medium-3 grid-sizer'; break; case 3: case 7: case 12: $imagesize = array("360", "806"); $articlesize = 'small-12 medium-3'; break; } } } ?> <article class="product-category item <?php echo $articlesize; ?> columns <?php echo $animation; ?> "> <a href="<?php echo get_term_link($category->slug, 'product_cat'); ?> "> <?php $small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_catalog'); $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true); if ($thumbnail_id) { $image = wp_get_attachment_image_src($thumbnail_id, 'full'); $image_src = $image[0]; $image = aq_resize($image_src, $imagesize[0], $imagesize[1], true, true, true); } else { $image = wc_placeholder_img_src(); } if ($image_src) { echo '<img src="' . $image . '" alt="' . esc_attr($category->name) . '" width="' . $imagesize[0] . '" height="' . $imagesize[1] . '" />'; } ?> <div class="title"> <h2><?php echo $category->name; if ($category->count > 0) { echo apply_filters('woocommerce_subcategory_count_html', ' <span class="count">(' . $category->count . ')</span>', $category); } ?> </h2> </div> </a> </article> <?php $i++; } ?> </div> <?php } woocommerce_reset_loop(); ?> <?php } else { ?> <?php $product_id_array = explode(',', $product_ids); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'post__in' => $product_id_array, 'posts_per_page' => "-1"); $products = new WP_Query($args); if ($products->have_posts()) { ?> <div class="grid products"> <?php while ($products->have_posts()) { $products->the_post(); if ($style == "style1") { switch ($i) { case 1: case 6: case 11: case 16: $imagesize = array("1440", "800"); $articlesize = 'small-12 medium-8'; break; case 2: case 7: case 12: case 17: $imagesize = array("720", "406"); $articlesize = 'small-12 medium-4 grid-sizer'; break; case 4: case 5: case 9: case 10: case 14: case 15: $imagesize = array("720", "400"); $articlesize = 'small-12 medium-4'; break; case 3: case 8: case 13: case 18: $imagesize = array("720", "800"); $articlesize = 'small-12 medium-4'; break; } } else { if ($style == "style2") { switch ($i) { case 1: case 13: $imagesize = array("720", "798"); $articlesize = 'small-12 medium-6'; break; case 2: case 4: case 5: case 6: case 9: case 8: case 10: case 11: case 14: case 15: $imagesize = array("360", "400"); $articlesize = 'small-12 medium-3 grid-sizer'; break; case 3: case 7: case 12: $imagesize = array("360", "806"); $articlesize = 'small-12 medium-3'; break; } } } global $product, $post; $catalog_mode = ot_get_option('shop_catalog_mode', 'off'); ?> <article itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?> " id="product-<?php the_ID(); ?> " <?php post_class($articlesize . ' columns post product item ' . $animation . ''); ?> > <?php if (has_post_thumbnail()) { $thumbnail_id = get_post_thumbnail_id(); $image = wp_get_attachment_image_src($thumbnail_id, 'full'); $image_src = $image[0]; $image = aq_resize($image_src, $imagesize[0], $imagesize[1], true, true, true); } ?> <figure class="overlay-effect"> <img src="<?php echo $image; ?> " width="<?php echo $imagesize[0]; ?> " height="<?php echo $imagesize[1]; ?> " /> <div class="overlay"> <div class="table"> <div> <div class="child post-title<?php if ($catalog_mode == 'on') { echo ' catalog-mode'; } ?> "> <h4><a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a><hr></h4> </div> <?php if ($catalog_mode != 'on') { ?> <div class="child buttons"> <?php /** * woocommerce_after_shop_loop_item_title hook * * @hooked woocommerce_template_loop_price - 10 */ do_action('woocommerce_after_shop_loop_item_title'); ?> <?php do_action('woocommerce_after_shop_loop_item'); ?> </div> <?php } ?> </div> </div> </div> </figure> </article> <?php $i++; } ?> </div><?php } } ?> <?php $out = ob_get_contents(); if (ob_get_contents()) { ob_end_clean(); } wp_reset_query(); wp_reset_postdata(); return $out; }
function shortcode_mc_6_1_products_grid($atts) { global $grid_products, $grid_product_details; extract(shortcode_atts(array('title' => '', 'shortcode_name' => '', 'ids' => '', 'skus' => '', 'category' => '', 'orderby' => '', 'order' => 'desc', 'per_page' => '7', 'el_class' => ''), $atts)); $shortcode_attributes = array(); $per_page = 7; switch ($shortcode_name) { case 'products_ids': $shortcode_attributes['ids'] = $ids; $shortcode_name = 'products'; break; case 'products_skus': $shortcode_attributes['skus'] = $skus; $shortcode_attributes['columns'] = $columns; $shortcode_name = 'products'; break; case 'product_category': $shortcode_attributes['category'] = $category; $shortcode_attributes['per_page'] = $per_page; break; case 'recent_products': case 'featured_products': case 'best_selling_products': case 'sale_products': case 'top_rated_products': $shortcode_attributes['per_page'] = $per_page; break; } if ($shortcode_name != 'best_selling_products') { $shortcode_attributes['orderby'] = $orderby; $shortcode_attributes['order'] = $order; } $grid_products = MC_6_1_Products_Grid::get_products($shortcode_name, $shortcode_attributes); $grid_product_details['title'] = $title; $grid_product_details['el_class'] = $el_class; $grid_product_details['grid_id'] = sanitize_title($title); $plugin_dir = dirname(MC_VC_PLUGIN_FILE_PATH); include $plugin_dir . '/templates/products-grid/mc_6_1_products_grid.php'; woocommerce_reset_loop(); wp_reset_postdata(); }
function rt_product_category_shortcode($atts) { global $woocommerce_loop, $page_product_count; if (empty($atts)) { return ''; } extract(shortcode_atts(array('per_page' => '12', 'columns' => '4', 'orderby' => 'title', 'order' => 'desc', 'category' => '', 'operator' => 'IN'), $atts)); if (!$category) { return ''; } // Default ordering args $ordering_args = WC()->query->get_catalog_ordering_args($orderby, $order); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $ordering_args['orderby'], 'order' => $ordering_args['order'], 'posts_per_page' => $per_page, 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')), 'tax_query' => array(array('taxonomy' => 'product_cat', 'terms' => array(esc_attr($category)), 'field' => 'slug', 'operator' => $operator))); if (isset($ordering_args['meta_key'])) { $args['meta_key'] = $ordering_args['meta_key']; } ob_start(); $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts)); //get product counts $page_product_count = $products->post_count; $woocommerce_loop['columns'] = $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 } woocommerce_reset_loop(); wp_reset_postdata(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }
function ux_product_categories_grid($atts, $content = null) { extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'parent' => '', 'hover' => '', 'description' => '', 'height' => '', 'parallax' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } ob_start(); ?> <div class="row"> <?php /** * Check if WooCommerce is active **/ if (function_exists('wc_print_notices')) { ?> <?php if ($product_categories) { foreach ($product_categories as $category) { woocommerce_get_template('content-product_cat_featured.php', array('category' => $category)); } } woocommerce_reset_loop(); ?> <?php } ?> </div> <?php $content = ob_get_contents(); ob_end_clean(); return $content; }
function mr_tailor_product_categories_einhornified($atts) { extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'parent' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } ob_start(); $cat_counter = 0; $cat_number = count($product_categories); if ($product_categories) { foreach ($product_categories as $category) { $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true); $image = wp_get_attachment_url($thumbnail_id); $cat_class = ""; $cat_counter++; switch ($cat_number) { case 1: $cat_class = "one_cat_" . $cat_counter; break; case 2: $cat_class = "two_cat_" . $cat_counter; break; case 3: $cat_class = "three_cat_" . $cat_counter; break; case 4: $cat_class = "four_cat_" . $cat_counter; break; case 5: $cat_class = "five_cat_" . $cat_counter; break; default: if ($cat_counter < 7) { $cat_class = $cat_counter; } else { $cat_class = "more_than_6"; } } ?> <?php if ($category->count == 1) { $query_args = array('showposts' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $category->slug))); $r = new WP_Query($query_args); if ($r->have_posts()) { ?> <?php while ($r->have_posts()) { $r->the_post(); global $product; $category_link = get_permalink(); } ?> <?php // Reset the global $the_post as this query will have stomped on it wp_reset_query(); } else { $category_link = $category_link = get_term_link($category->slug, 'product_cat'); } } else { $category_link = get_term_link($category->slug, 'product_cat'); } $term_id = get_queried_object()->term_id; $post_id = 'product_cat_' . $category->term_id; $gif_url = get_field('gif_category_image', $post_id) != "" ? "url(" . get_field('gif_category_image', $post_id) . ")" : "none"; ?> <div class="category_<?php echo $cat_class; ?> Test"> <div class="category_grid_box"> <span class="category_item_bkg" data-imgsrc="<?php echo $gif_url; ?> " style="background-image:url(<?php echo $image; ?> )"></span> <a href="<?php echo $category_link; ?> " class="category_item" > <span class="category_name"><?php // echo $category->name; ?> </span> </a> </div> </div> <?php } ?> <div class="clearfix"></div> <?php } woocommerce_reset_loop(); return '<div class="row"><div class="categories_grid test">' . ob_get_clean() . '</div></div>'; }
function product_loop($query_args, $atts, $loop_name) { global $woocommerce_loop; $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $query_args, $atts)); $columns = absint($atts['columns']); $slider = $atts['slider'] ? $atts['slider'] : 'col-sm-4 col-md-3'; $woocommerce_loop['columns'] = $columns; ob_start(); if ($products->have_posts()) { ?> <?php do_action("woocommerce_shortcode_before_{$loop_name}_loop"); ?> <?php woocommerce_product_loop_start(); ?> <?php while ($products->have_posts()) { $products->the_post(); ?> <div class="<?php echo $slider; ?> "> <?php if (!empty($slider)) { ?> <div class="products grid-v2"> <?php } //if ( !is_singular() && is_main_query() ) { remove_action('woocommerce_after_shop_loop_item', 'print_wishlist_link', 30); remove_action('woocommerce_after_shop_loop_item', 'cr_woocommerce_discount', 50); remove_action('woocommerce_after_shop_loop_item', 'cr_woocommerce_pick_up_in_store', 60); remove_action('woocommerce_after_shop_loop_item', 'cr_woocommerce_shipping_in_home', 70); //} ?> <?php wc_get_template_part('content', 'product'); if (!is_singular() && is_main_query()) { add_action('woocommerce_after_shop_loop_item', 'cr_woocommerce_discount', 50); add_action('woocommerce_after_shop_loop_item', 'print_wishlist_link', 30); add_action('woocommerce_after_shop_loop_item', 'cr_woocommerce_pick_up_in_store', 60); add_action('woocommerce_after_shop_loop_item', 'cr_woocommerce_shipping_in_home', 70); } ?> <?php if (!empty($slider)) { ?> </div> <?php } ?> </div> <?php } // end of the loop. ?> <?php woocommerce_product_loop_end(); ?> <?php do_action("woocommerce_shortcode_after_{$loop_name}_loop"); ?> <?php } woocommerce_reset_loop(); wp_reset_postdata(); if (empty($slider)) { return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; } else { return ob_get_clean(); } }
/** * List products in a category shortcode * * @access public * @param array $atts * @return string */ public static function wcmp_show_product_category($atts) { global $woocommerce_loop, $WCMp; extract(shortcode_atts(array('vendor' => '', 'per_page' => '12', 'columns' => '4', 'orderby' => 'title', 'order' => 'desc', 'category' => '', 'operator' => 'IN'), $atts)); if (!$category) { return ''; } // Default ordering args $ordering_args = WC()->query->get_catalog_ordering_args($orderby, $order); $args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $ordering_args['orderby'], 'order' => $ordering_args['order'], 'posts_per_page' => $per_page, 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')), 'tax_query' => array(array('taxonomy' => 'product_cat', 'terms' => array_map('sanitize_title', explode(',', $category)), 'field' => 'slug', 'operator' => $operator))); if (!empty($vendor)) { $args['tax_query'][] = array('taxonomy' => $WCMp->taxonomy->taxonomy_name, 'field' => 'slug', 'terms' => sanitize_title($vendor)); } if (isset($ordering_args['meta_key'])) { $args['meta_key'] = $ordering_args['meta_key']; } ob_start(); $products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts)); $woocommerce_loop['columns'] = $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 } woocommerce_reset_loop(); wp_reset_postdata(); $return = '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; // Remove ordering query arguments WC()->query->remove_ordering_args(); return $return; }
function krypton_product_categories($atts, $content = null) { global $woocommerce_loop, $dt_featured, $krypton_Scripts; if (!isset($dt_featured)) { $dt_featured = 1; } else { $dt_featured++; } extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'DESC', 'columns' => '4', 'hide_empty' => 1, 'parent' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $widgetID = "featured" . $dt_featured; $woocommerce_loop['columns'] = 1; $compile = ''; $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { wp_register_script('owl.carousel', get_template_directory_uri() . '/js/owl.carousel.js', array('jquery'), '', false); wp_enqueue_script('owl.carousel'); $compile = '<div class="dt-shop-category"> <div class="row"><div id="' . $widgetID . '" class="shop-items">'; foreach ($product_categories as $category) { ob_start(); wc_get_template('content-product_cat_carousel.php', array('category' => $category)); $wooitem = ob_get_contents(); ob_end_clean(); $compile .= $wooitem; } woocommerce_reset_loop(); $compile .= '</div></div></div>'; $script = 'jQuery(document).ready(function($) { \'use strict\'; var ' . $widgetID . ' = $("#' . $widgetID . '.shop-items"); var navigation=$(\'<div></div>\').addClass(\'owl-carousel-navigation\'), prevBtn=$(\'<a></a>\').addClass(\'btn btn-owl\'), nextBtn=prevBtn.clone(); navigation.append(prevBtn.addClass(\'prev\'),nextBtn.addClass(\'next\')); ' . $widgetID . '.parent().append(navigation); try{ ' . $widgetID . '.owlCarousel({ items : ' . $columns . ', itemsDesktop : [1200,' . max(min('3', $columns - 1), 1) . '], itemsDesktopSmall : [1023,' . max(min('2', $columns - 1), 1) . '], itemsTablet : [768,' . max(min('2', $columns - 1), 1) . '], itemsMobile : [600,1], pagination : false, slideSpeed : 400}); nextBtn.click(function(){ ' . $widgetID . '.trigger(\'owl.next\'); }); prevBtn.click(function(){ ' . $widgetID . '.trigger(\'owl.prev\'); }); ' . $widgetID . '.owlCarousel(\'reload\'); } catch(err){} });'; array_push($krypton_Scripts, $script); return '<div class="container woocommerce">' . $compile . '</div>'; } woocommerce_reset_loop(); return ''; }
function ux_product_categories($atts, $content = null) { $sliderrandomid = rand(); extract(shortcode_atts(array('number' => null, 'title' => '', 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1, 'parent' => ''), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; ?> <?php /** * Check if WooCommerce is active **/ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { ?> <?php slider_script($sliderrandomid, $columns); ?> <?php if ($title) { ?> <div class="row"> <div class="large-12 columns"> <h3 class="section-title"><span><?php echo $title; ?> </span></h3> </div> </div><!-- end .title --> <?php } ?> <div class="row column-slider category-slider"> <div id="slider_<?php echo $sliderrandomid; ?> " class="iosSlider" style="overflow:hidden;height:100px;min-height:100px;"> <ul class="slider large-block-grid-<?php echo $columns; ?> small-block-grid-2 ux-latest-products"> <?php if ($product_categories) { foreach ($product_categories as $category) { woocommerce_get_template('content-product_cat.php', array('category' => $category)); } } woocommerce_reset_loop(); ?> </ul> <!-- .slider --> <div class="sliderControlls"> <div class="sliderNav small hide-for-small"> <a href="javascript:void(0)" class="nextSlide disabled prev_<?php echo $sliderrandomid; ?> "><span class="icon-angle-left"></span></a> <a href="javascript:void(0)" class="prevSlide next_<?php echo $sliderrandomid; ?> "><span class="icon-angle-right"></span></a> </div> </div><!-- .sliderControlls --> </div> <!-- .iOsslider --> </div><!-- .row .column-slider --> <?php } ?> <?php $content = ob_get_contents(); ob_end_clean(); return $content; }
/** * Loop over found products. * * @since 1.0.0 * @param array $query_args \WP_Query arguments. * @param array $atts User defined attributes in shortcode tag. * @return string Current buffer contents. */ private function get_products($query_args, $atts) { global $woocommerce_loop; $category = \sanitize_title($atts['category']); $taxonomy = \sanitize_text_field($atts['taxonomy']); $columns = absint($atts['columns']); $woocommerce_loop['columns'] = $columns; $products = new \WP_Query($query_args); ob_start(); if ($products->have_posts()) { \do_action('woocommerce_shortcode_before_featured_products_by_category', $category, $taxonomy); \woocommerce_product_loop_start(); while ($products->have_posts()) { $products->the_post(); \wc_get_template_part('content', 'product'); } \woocommerce_product_loop_end(); \do_action('woocommerce_shortcode_after_featured_products_by_category', $category, $taxonomy); } \woocommerce_reset_loop(); \wp_reset_postdata(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }
/** * List all (or limited) product categories * * @access public * @param array $atts * @return string */ function woocommerce_product_categories($atts) { global $woocommerce_loop; extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 1), $atts)); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; $args = array('number' => $number, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids); $product_categories = get_terms('product_cat', $args); $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { echo '<ul class="products">'; foreach ($product_categories as $category) { woocommerce_get_template('content-product_cat.php', array('category' => $category)); } echo '</ul>'; } wp_reset_query(); woocommerce_reset_loop(); return ob_get_clean(); }
function woocomposer_grid_shortcode($atts) { global $woocommerce_loop; $number = $orderby = $order = $columns = $options = $parent = $design_style = $text_align = $border_style = $border_color = ''; $border_size = $border_radius = $product_animation = $color_categories = $size_cat = $img_animate = $color_categories_bg = ''; $color_cat_count_color = $color_cat_count_bg = $cat_count = ''; extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'ids' => '', 'options' => '', 'cat_count' => '', 'design_style' => '', 'text_align' => '', 'border_style' => '', 'border_color' => '', 'border_size' => '', 'border_radius' => '', 'product_animation' => '', 'color_categories_bg' => '', 'color_categories' => '', 'color_cat_count_bg' => '', 'color_cat_count_color' => '', 'size_cat' => '', 'img_animate' => ''), $atts)); $border = $size = $count_style = ''; $opts = explode(",", $options); if ($color_categories !== '') { $size .= 'color:' . $color_categories . ';'; } if ($color_categories_bg !== '') { $size .= 'background:' . $color_categories_bg . ';'; } if ($size_cat !== '') { $size .= 'font-size:' . $size_cat . 'px;'; } if ($color_cat_count_bg !== '') { $count_style .= 'background:' . $color_cat_count_bg . ';'; } if ($color_cat_count_color !== '') { $count_style .= 'color:' . $color_cat_count_color . ';'; } if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = in_array('hide_empty', $opts) ? 1 : 0; $parent = in_array('parent', $opts) ? '' : 0; if ($border_style !== '') { $border .= 'border:' . $border_size . 'px ' . $border_style . ' ' . $border_color . ';'; $border .= 'border-radius:' . $border_radius . 'px;'; } // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { //woocommerce_product_loop_start(); echo '<ul class="wcmp-cat-grid products">'; foreach ($product_categories as $category) { // Store loop count we're currently on if (empty($woocommerce_loop['loop'])) { $woocommerce_loop['loop'] = 0; } // Store column count for displaying the grid if (empty($woocommerce_loop['columns'])) { $woocommerce_loop['columns'] = apply_filters('loop_shop_columns', 4); } // Increase loop count $woocommerce_loop['loop']++; ?> <li class="product-category product<?php if (($woocommerce_loop['loop'] - 1) % $woocommerce_loop['columns'] == 0 || $woocommerce_loop['columns'] == 1) { echo ' first'; } if ($woocommerce_loop['loop'] % $woocommerce_loop['columns'] == 0) { echo ' last'; } ?> "> <div class="wcmp-product wcmp-img-<?php echo $img_animate; ?> wcmp-cat-<?php echo $design_style . ' animated ' . $product_animation; ?> " style="<?php echo $border; ?> "> <?php do_action('woocommerce_before_subcategory', $category); ?> <a href="<?php echo get_term_link($category->slug, 'product_cat'); ?> " style="text-align:<?php echo $text_align; ?> ;"> <div class="wcmp-product-image"> <?php /** * woocommerce_before_subcategory_title hook * * @hooked woocommerce_subcategory_thumbnail - 10 */ do_action('woocommerce_before_subcategory_title', $category); ?> </div><!--.wcmp-product-image--> <h3 style="<?php echo $size; ?> "> <?php echo $category->name; if ($category->count > 0) { echo apply_filters('woocommerce_subcategory_count_html', ' <mark class="count" style="' . $count_style . '">' . $category->count . ' ' . $cat_count . '</mark>', $category); } ?> </h3> <?php /** * woocommerce_after_subcategory_title hook */ do_action('woocommerce_after_subcategory_title', $category); ?> </a> <?php do_action('woocommerce_after_subcategory', $category); ?> </div><!--.wcmp-product--> </li> <?php } woocommerce_product_loop_end(); } woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }
" alt=""> </div> <?php } ?> </div> </div> <?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(); } woocommerce_reset_loop(); wp_reset_postdata(); echo '<div class="woocommerce wc-product-grid columns-' . $columns . '">' . ob_get_clean() . '</div>';
function mystile_product_categories() { global $woo_options; if (class_exists('woocommerce') && $woo_options['woo_homepage_product_categories'] == "true") { echo '<h1>' . __('Product Categories', 'woothemes') . '</h1>'; echo do_shortcode('[product_categories number=""]'); woocommerce_reset_loop(); // can be removed post WooCommerce 1.6.4 } // End query to see if products should be displayed }
function snpshpwp_product_categories($atts, $content = null) { extract(shortcode_atts(array('ids' => '', 'per_page' => 4, 'columns' => '4', 'orderby' => 'date', 'order' => 'DESC', 'bot_margin' => 36, 'hide_empty' => 1, 'parent' => '', 'class' => '', 'shortcode_id' => '', 'animate' => 'none', 'animation_delay' => 0, 'animation_group' => ''), $atts)); if ($ids == '') { return __('Please select categories', 'snpshpwp'); } $bot_margin = (int) $bot_margin; $margin = ' style="margin-bottom:' . $bot_margin . 'px"'; $out = ''; global $woocommerce_loop; if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $hide_empty == true || $hide_empty == 1 ? 1 : 0; $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => 1, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent, 'parent' => ''); $product_categories = get_terms('product_cat', $args); $cat_num = count($product_categories); $product_categories = array_slice($product_categories, 0, $rows * $columns); $pagination = snpshpwp_mini_woo_pagination_cat($cat_num, 1, $rows * $columns, 'yes'); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } $woocommerce_loop['columns'] = $columns; ob_start(); $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { woocommerce_product_loop_start(); foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } woocommerce_product_loop_end(); } woocommerce_reset_loop(); $shortcode = ob_get_clean(); $out .= '<div class="snpshpwp_woo_wrap div_touch_optimized snpshpwp_div_inherit_width"' . $margin . ' data-shortcode="' . $bot_margin . '|' . $columns . '|' . $per_page . '|' . $order . '|' . $orderby . '|' . implode(',', $ids) . '">' . do_shortcode($shortcode) . $pagination . '</div>'; return $out; }
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; }
function thb_product_categories($atts, $content = null) { extract(shortcode_atts(array('carousel' => 'no', 'columns' => '4', 'cat' => ''), $atts)); global $woocommerce, $woocommerce_loop; $args = $product_categories = array(); $cats = explode(",", $cat); foreach ($cats as $cat) { $c = get_term_by('slug', $cat, 'product_cat'); array_push($product_categories, $c); } $woocommerce_loop['columns'] = apply_filters('loop_shop_columns', $columns); ob_start(); ?> <?php if ($carousel == "yes") { ?> <div class="carousel-container"> <div class="carousel products owl row" data-columns="<?php echo $columns; ?> " data-navigation="true"> <?php if ($product_categories) { foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } } woocommerce_reset_loop(); ?> </div> </div> <?php } else { ?> <?php switch ($columns) { case 2: $col = 'two'; break; case 3: $col = 'three'; break; case 4: $col = 'four'; break; } ?> <div class="products row <?php echo $col; ?> -columns" data-equal=".product-category"> <?php if ($product_categories) { foreach ($product_categories as $category) { wc_get_template('content-product_cat.php', array('category' => $category)); } } woocommerce_reset_loop(); ?> </div> <?php } ?> <?php $out = ob_get_contents(); if (ob_get_contents()) { ob_end_clean(); } return $out; }
function woocomposer_carousel_shortcode($atts) { global $woocommerce_loop; $number = $orderby = $order = $columns = $options = $parent = $design_style = $text_align = $border_style = $border_color = ''; $border_size = $border_radius = $product_animation = $color_categories = $size_cat = $img_animate = $color_categories_bg = $cat_count = ''; $slides_to_scroll = $scroll_speed = $advanced_opts = $output = $autoplay_speed = $scroll_opts = $color_cat_count_color = $color_cat_count_bg = ''; extract(shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'ids' => '', 'options' => '', 'cat_count' => '', 'design_style' => '', 'text_align' => '', 'border_style' => '', 'border_color' => '', 'border_size' => '', 'border_radius' => '', 'product_animation' => '', 'color_categories_bg' => '', 'color_categories' => '', 'color_cat_count_bg' => '', 'color_cat_count_color' => '', 'size_cat' => '', 'slides_to_scroll' => '1', 'scroll_speed' => '1000', 'advanced_opts' => '', 'autoplay_speed' => '500', 'scroll_opts' => '', 'img_animate' => ''), $atts)); $border = $size = $count_style = ''; $opts = explode(",", $options); $infinite = $autoplay = $dots = 'false'; if ($product_animation !== '') { $product_animation = 'animated ' . $product_animation . ' '; } $uid = uniqid(); $advanced_opts = explode(",", $advanced_opts); if (in_array("infinite", $advanced_opts)) { $infinite = 'true'; } if (in_array("autoplay", $advanced_opts)) { $autoplay = 'true'; } if (in_array("dots", $advanced_opts)) { $dots = 'true'; } if ($color_categories !== '') { $size .= 'color:' . $color_categories . ';'; } if ($color_categories_bg !== '') { $size .= 'background:' . $color_categories_bg . ';'; } if ($size_cat !== '') { $size .= 'font-size:' . $size_cat . 'px;'; } if ($color_cat_count_bg !== '') { $count_style .= 'background:' . $color_cat_count_bg . ';'; } if ($color_cat_count_color !== '') { $count_style .= 'color:' . $color_cat_count_color . ';'; } if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = in_array('hide_empty', $opts) ? 1 : 0; $parent = in_array('parent', $opts) ? '' : 0; if ($border_style !== '') { $border .= 'border:' . $border_size . 'px ' . $border_style . ' ' . $border_color . ';'; $border .= 'border-radius:' . $border_radius . 'px;'; } // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'include' => $ids, 'pad_counts' => true, 'child_of' => $parent); $product_categories = get_terms('product_cat', $args); if ($parent !== "") { $product_categories = wp_list_filter($product_categories, array('parent' => $parent)); } if ($hide_empty) { foreach ($product_categories as $key => $category) { if ($category->count == 0) { unset($product_categories[$key]); } } } if ($number) { $product_categories = array_slice($product_categories, 0, $number); } $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_categories) { //woocommerce_product_loop_start(); foreach ($product_categories as $category) { $vc_span = ''; if ($columns == "2") { $vc_span = 'vc_span6 wpb_column column_container'; } elseif ($columns == "3") { $vc_span = 'vc_span4 wpb_column column_container'; } elseif ($columns == "4") { $vc_span = 'vc_span3 wpb_column column_container'; } echo '<div id="wcmp-category-' . uniqid() . '" class="wooproduct">'; // Store loop count we're currently on if (empty($woocommerce_loop['loop'])) { $woocommerce_loop['loop'] = 0; } // Store column count for displaying the grid if (empty($woocommerce_loop['columns'])) { $woocommerce_loop['columns'] = apply_filters('loop_shop_columns', 4); } // Increase loop count $woocommerce_loop['loop']++; ?> <div class="wcmp-carousel-item <?php $product_animation; ?> product-category <?php if (($woocommerce_loop['loop'] - 1) % $woocommerce_loop['columns'] == 0 || $woocommerce_loop['columns'] == 1) { echo ' first'; } if ($woocommerce_loop['loop'] % $woocommerce_loop['columns'] == 0) { echo ' last'; } ?> " style="<?php //echo $border; ?> "> <div class="wcmp-product wcmp-img-<?php echo $img_animate; ?> woocommerce wcmp-cat-<?php echo $design_style; ?> "> <?php do_action('woocommerce_before_subcategory', $category); ?> <a href="<?php echo get_term_link($category->slug, 'product_cat'); ?> " style="text-align:<?php echo $text_align; ?> ;"> <div class="wcmp-product-image"> <?php do_action('woocommerce_before_subcategory_title', $category); ?> </div><!--.wcmp-product-image--> <h3 style="<?php echo $size; ?> "> <?php echo $category->name; if ($category->count > 0) { echo apply_filters('woocommerce_subcategory_count_html', ' <mark class="count" style="' . $count_style . '">' . $category->count . ' ' . $cat_count . '</mark>', $category); } ?> </h3> <?php do_action('woocommerce_after_subcategory_title', $category); ?> </a> <?php do_action('woocommerce_after_subcategory', $category); ?> </div> </div> <?php echo '</div>'; } //woocommerce_product_loop_end(); } woocommerce_reset_loop(); ?> <script type="text/javascript"> jQuery(document).ready(function(e) { jQuery("#woo-carousel-<?php echo $uid; ?> > .woocomposer").slick({ infinite: <?php echo $infinite; ?> , slidesToShow: <?php echo $columns; ?> , slidesToScroll: <?php echo $slides_to_scroll; ?> , speed: <?php echo $scroll_speed; ?> , dots: <?php echo $dots; ?> , autoplay: <?php echo $autoplay; ?> , autoplaySpeed: <?php echo $autoplay_speed; ?> , responsive: [{ breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 3, infinite: true, dots: true } }, { breakpoint: 600, settings: { slidesToShow: 2, slidesToScroll: 2 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1 } }] }); }); </script> <?php $output = '<div id="woo-carousel-' . $uid . '" class="woocommerce woocomposer_carousel wcmp-cat-carousel">'; $output .= '<div class="woocomposer" data-columns="' . $columns . '">'; $output .= ob_get_clean(); $output .= '</div>'; $output .= '</div>'; return $output; }
/** * List all (or limited) product atributes * * @param array $atts * @return string */ function product_attributes($atts) { global $woocommerce_loop; $atts = shortcode_atts(array('number' => null, 'orderby' => 'name', 'order' => 'ASC', 'columns' => '4', 'hide_empty' => 0, 'attribute' => '', 'ids' => ''), $atts); if (isset($atts['ids'])) { $ids = explode(',', $atts['ids']); $ids = array_map('trim', $ids); } else { $ids = array(); } $hide_empty = $atts['hide_empty'] == true || $atts['hide_empty'] == 1 ? 1 : 0; // get terms and workaround WP bug with parents/pad counts $args = array('orderby' => $atts['orderby'], 'order' => $atts['order'], 'hide_empty' => $hide_empty, 'include' => $ids, 'number' => $atts['number'], 'pad_counts' => true); $product_attributes = get_terms('pa_' . $atts['attribute'], $args); if ($hide_empty) { foreach ($product_attributes as $key => $attribute) { if ($attribute->count == 0) { unset($product_attributes[$key]); } } } if ($atts['number']) { $product_attributes = array_slice($product_attributes, 0, $atts['number']); } $columns = absint($atts['columns']); $woocommerce_loop['columns'] = $columns; ob_start(); // Reset loop/columns globals when starting a new loop $woocommerce_loop['loop'] = $woocommerce_loop['column'] = ''; if ($product_attributes) { woocommerce_product_loop_start(); //print_r($product_attributes); foreach ($product_attributes as $attribute) { wc_get_template('content-product_attribute.php', array('attribute' => $attribute)); } woocommerce_product_loop_end(); } woocommerce_reset_loop(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }