/** * Defines [show_categories] shortcode * * @global type $cat_shortcode_query * @param type $atts * @return string */ function product_cat_shortcode($atts) { global $cat_shortcode_query, $product_sort, $archive_template; $cat_shortcode_query = array(); $cat_shortcode_query['current'] = 0; $args = shortcode_atts(array('exclude' => array(), 'include' => array(), 'archive_template' => get_option('archive_template', 'default'), 'parent' => '', 'sort' => 0, 'shortcode_query' => 'yes'), $atts); $div = '<div class="product-subcategories ' . $args['archive_template'] . ' ' . product_list_class('category-list') . '">'; $cats = get_terms('al_product-cat', $args); $cat_shortcode_query['count'] = count($cats); $cat_shortcode_query['enable'] = $args['shortcode_query']; $product_sort = intval($args['sort']); $inside = ''; if ($args['parent'] == '' && empty($args['include'])) { $old_args = $args; $args['parent'] = 0; $cats = get_terms('al_product-cat', $args); foreach ($cats as $cat) { $inside .= get_product_category_template($args['archive_template'], $cat); $cat_shortcode_query['current']++; $inside .= get_sub_product_subcategories($args, $cat); } } else { foreach ($cats as $cat) { $inside .= get_product_category_template($args['archive_template'], $cat); $cat_shortcode_query['current']++; } } if (!empty($inside)) { do_action('before_category_list', $archive_template); $inside = $div . $inside; $inside .= '</div>'; } reset_row_class(); return $inside; }
function product_cat_shortcode($atts) { global $cat_shortcode_query; $cat_shortcode_query = array(); $cat_shortcode_query['current'] = 0; $args = shortcode_atts(array('exclude' => array(), 'include' => array(), 'archive_template' => get_option('archive_template', 'default'), 'parent' => ''), $atts); $inside = '<div class="product-subcategories ' . $args['archive_template'] . ' ' . product_list_class() . '">'; $cats = get_terms('al_product-cat', $args); $cat_shortcode_query['count'] = count($cats); if ($args['parent'] == '') { $old_args = $args; $args['parent'] = 0; $cats = get_terms('al_product-cat', $args); foreach ($cats as $cat) { $inside .= get_product_category_template($args['archive_template'], $cat); $cat_shortcode_query['current']++; $inside .= get_sub_product_subcategories($args, $cat); } } else { foreach ($cats as $cat) { $inside .= get_product_category_template($args['archive_template'], $cat); $cat_shortcode_query['current']++; } } $inside .= '</div>'; reset_row_class(); return $inside; }
/** * Defines [show_categories] shortcode * * @global type $cat_shortcode_query * @param type $atts * @return string */ function product_cat_shortcode($atts) { global $cat_shortcode_query, $product_sort, $archive_template; $cat_shortcode_query = array(); $cat_shortcode_query['current'] = 0; $args = shortcode_atts(array('exclude' => array(), 'include' => array(), 'archive_template' => get_option('archive_template', 'default'), 'parent' => '', 'sort' => 0, 'shortcode_query' => 'yes', 'orderby' => 'name', 'order' => 'ASC'), $atts); if ($args['orderby'] == 'none') { $args['orderby'] = 'include'; } $args = apply_filters('show_categories_args', $args); if (!is_array($args['include'])) { $args['include'] = explode(',', $args['include']); } $div = '<div class="product-subcategories responsive ' . $args['archive_template'] . ' ' . product_list_class($args['archive_template'], 'category-list') . '">'; $cats = get_terms('al_product-cat', $args); $cat_shortcode_query['count'] = count($cats); $cat_shortcode_query['enable'] = $args['shortcode_query']; $product_sort = intval($args['sort']); $inside = ''; if ($args['parent'] == '' && empty($args['include'])) { $old_args = $args; $args['parent'] = 0; $cats = get_terms('al_product-cat', $args); foreach ($cats as $cat) { $inside .= get_product_category_template($args['archive_template'], $cat); $cat_shortcode_query['current']++; $inside .= get_sub_product_subcategories($args, $cat); } } else { foreach ($cats as $cat) { $inside .= get_product_category_template($args['archive_template'], $cat); $cat_shortcode_query['current']++; } } if (!empty($inside)) { $ready = apply_filters('category_list_ready', $inside, $args['archive_template']); ob_start(); do_action('before_category_list', $args['archive_template']); $inside = ob_get_contents(); ob_end_clean(); $inside .= $div . $ready; $inside .= '</div>'; } reset_row_class(); return $inside; }
/** * Returns realted products * * @global object $post * @param int $products_limit * @param boolean $markup * @return string */ function get_related_products($products_limit = null, $markup = false) { if (!isset($products_limit)) { $products_limit = get_current_per_row(); } $current_product_id = get_the_ID(); $taxonomy = get_current_screen_tax(); $post_type = get_current_screen_post_type(); $terms = get_the_terms($current_product_id, $taxonomy); if (is_array($terms) && !empty($taxonomy) && !empty($post_type)) { $terms = array_reverse($terms); $archive_template = get_product_listing_template(); $i = 0; $inside = ''; $products = array(); foreach ($terms as $term) { $query_param = array('post_type' => $post_type, 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $term->slug)), 'posts_per_page' => $products_limit); $query = new WP_Query($query_param); while ($query->have_posts()) { $query->the_post(); global $post; if ($current_product_id != $post->ID) { $i++; $products[] = $post->ID; } if ($i >= $products_limit) { break; } } wp_reset_postdata(); reset_row_class(); if ($i >= $products_limit) { break; } } $div = ''; if (!empty($products)) { $products = implode(',', $products); if ($markup) { $div = '<div class="related-products">'; $single_names = get_single_names(); if (!empty($single_names['other_categories'])) { $div .= '<h2 class="catalog-header">' . $single_names['other_categories'] . '</h2>'; } $div .= do_shortcode('[show_products product="' . $products . '"]'); $div .= '</div>'; } else { $div = do_shortcode('[show_products product="' . $products . '"]'); } } return $div; } return; }
function show_products_outside_loop($atts) { global $shortcode_query, $product_sort, $archive_template; $args = shortcode_atts(array('post_type' => 'al_product', 'category' => '', 'product' => '', 'products_limit' => -1, 'archive_template' => get_product_listing_template(), 'design_scheme' => '', 'sort' => 0), $atts); $category = esc_html($args['category']); $product = esc_html($args['product']); $products_limit = intval($args['products_limit']); $archive_template = esc_attr($args['archive_template']); $design_scheme = esc_attr($args['design_scheme']); $product_sort = intval($args['sort']); if ($product != 0) { $product_array = explode(',', $product); $query_param = array('post_type' => 'al_product', 'post__in' => $product_array, 'posts_per_page' => $products_limit); } else { if (!empty($category)) { $category_array = explode(',', $category); $field = 'name'; if (is_numeric($category_array[0])) { $field = 'term_id'; } $query_param = array('post_type' => 'al_product', 'tax_query' => array(array('taxonomy' => 'al_product-cat', 'field' => $field, 'terms' => $category_array)), 'posts_per_page' => $products_limit); } else { $query_param = array('post_type' => 'al_product', 'posts_per_page' => $products_limit); } } $query_param = apply_filters('shortcode_query', $query_param); $shortcode_query = new WP_Query($query_param); $inside = ''; $i = 0; do_action('before_product_list', $archive_template); while ($shortcode_query->have_posts()) { $shortcode_query->the_post(); global $post; $i++; $inside .= get_catalog_template($archive_template, $post, $i, $design_scheme); } $inside = apply_filters('product_list_ready', $inside, $archive_template); wp_reset_postdata(); reset_row_class(); return '<div class="product-list responsive ' . $archive_template . '-list ' . product_list_class() . '">' . $inside . '<div style="clear:both"></div></div>'; }