Tabbed Category Product Listing for Woocommerce Shortcode

Below, you’ll find a detailed guide on how to add the Tabbed Category Product Listing for Woocommerce Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Tabbed Category Product Listing for Woocommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Tabbed Category Product Listing for Woocommerce Plugin and the shortcodes it provides:

Plugin Icon
Tabbed Category Product Listing for Woocommerce

"Tabbed Category Product Listing for Woocommerce is a powerful plugin that enhances your ecommerce experience. It simplifies product categorization and listing, making navigation easier for your customers."

★★★★☆ (26) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [wtcpl-product-cat]

Tabbed Category Product Listing for Woocommerce [wtcpl-product-cat] Shortcode

The Woo-Tabbed-Category-Product-Listing plugin shortcode, ‘wtcpl-product-cat’, dynamically loads products based on selected categories. It organizes products into tabs for each category, enhancing user navigation. This shortcode also provides options to control product display such as the number of products per page, column numbers, and whether to show empty categories. It also allows customization of the category order.

Shortcode: [wtcpl-product-cat]

Examples and Usage

Basic example – A simple usage of the shortcode to load products based on the defined settings in the plugin’s options.

[wtcpl-product-cat]

PHP Function Code

In case you have difficulties debugging what causing issues with [wtcpl-product-cat] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wtcpl-product-cat', 'wtcpl_load_products');

Shortcode PHP function:

function wtcpl_load_products()
    {


    $qc_woo_tabbed_shortcode_preview = get_option('qc_woo_tabbed_shortcode_preview');

    if($qc_woo_tabbed_shortcode_preview != 'enable'){

        if (is_admin()) {
            return;
        }

    }

       // if (!is_admin()) {
            ob_start();
            $product_number                     = esc_attr(get_option('product_number'));
            $column_number                      = esc_attr(get_option('column_number'));
            $qc_woo_tabbed_show_empty_category  = esc_attr(get_option('qc_woo_tabbed_show_empty_category')) == 'enable' ? 0 : 1;

            wtcpl_plugin_scripts();
            wtcpl_scroll_to_scripts();
            wtcpl_plugin_styles();
            ?>
            <div class="wtcpl_container">
                <div id="nav-holder">
                    <div class="wtcpl_category_nav" id="wtcpl_tabs">
                        <?php

                        $product_categories = unserialize(get_option('selected_categories'));

                        if(!empty($product_categories) ){

                            $category_orders = get_option('category_order');

                            if($category_orders == 'menu_order'){
                                $args = array(
                                    'number'        => '',
                                    'order'         => 'asc',
                                    'orderby'       => 'menu_order',
                                    'hide_empty'    => $qc_woo_tabbed_show_empty_category,
                                    'exclude'       => $product_categories,
                                    //'include'       => $category_ids,
                                );
                            }else if($category_orders == 'term_order'){
                                $args = array(
                                    'number'        => '',
                                    'order'         => 'asc',
                                    'orderby'       => 'term_order',
                                    'hide_empty'    => $qc_woo_tabbed_show_empty_category,
                                    'exclude'       => $product_categories,
                                    //'include'       => $category_ids,
                                );
                            }else{
                                $args = array(
                                    'number'        => '',
                                    'order'         => get_option('category_order'),
                                    'orderby'       => 'title',
                                    'hide_empty'    => $qc_woo_tabbed_show_empty_category,
                                    'exclude'       => $product_categories,
                                    //'include'       => $category_ids,
                                );

                            }

                        }else{

                            $category_orders = get_option('category_order');

                            if($category_orders == 'menu_order'){

                                $args = array(
                                    'number'        => '',
                                    'order'         => 'asc',
                                    'orderby'       => 'menu_order',
                                    'hide_empty'    => $qc_woo_tabbed_show_empty_category,
                                    'include'       => ''
                                );
                            }else if($category_orders == 'term_order'){

                                $args = array(
                                    'number'        => '',
                                    'order'         => 'asc',
                                    'orderby'       => 'term_order',
                                    'hide_empty'    => $qc_woo_tabbed_show_empty_category,
                                    'include'       => ''
                                );
                            }else{

                                $args = array(
                                    'number'        => '',
                                    'order'         => get_option('category_order'),
                                    'orderby'       => 'title',
                                    'hide_empty'    => $qc_woo_tabbed_show_empty_category,
                                    'include'       => ''
                                );

                            }
                        }
            // $product_categories = get_terms('product_cat', $args);

                        $product_categories = get_terms('product_cat', $args); ?>
                        <ul>
                            <?php
                            $i = 0;
                            foreach ($product_categories as $cat) {

                                $slug_url = (get_option('qcld_use_category_tab') == 'id') ? $cat->term_id : $cat->slug;


                                ?>
                                <li><a id="<?php echo esc_attr($slug_url); ?>"
                                       class="product-<?php echo esc_attr($slug_url); echo($i == 0 ? ' active' : ''); ?>" data-name="<?php echo esc_attr($cat->name); ?>" href="#">

                                        <?php
                                        if(!empty(get_option('qc_woo_tabbed_enable_category_image')) || ( isset($cat_image_on_top) && $cat_image_on_top == 'enable' ) ){
                                            qcld_get_category_image($cat->term_id); 
                                        }
                                        ?>
                                       <?php echo esc_attr(substr($cat->name, 0, get_option('max_char_per_cat'))); ?></a>
                                </li>
                                <?php
                                $i++;
                            }
                            wp_reset_query();
                            ?>
                        </ul>
                        <!--   <div class="clear"></div>-->
                    </div>
                </div>
                <div class="product_content" id="wtcpl_tabs_container">
                    <?php
                    $i = 0;
                    foreach ($product_categories as $cat) {
                        $slug_url = (get_option('qcld_use_category_tab') == 'id') ? $cat->term_id : $cat->slug;

                        ?>
                        <div class="each_cat<?php echo($i == 0 ? ' active' : ''); ?>" id="product-<?php echo esc_attr($slug_url); ?>">
                            <?php

                            $args_query = array(
                            'post_type'             => 'product',
                            'post_status'           => 'publish',
                            'tax_query'             => array(
                                                    'relation' => 'OR',
                                                    array(
                                                        'taxonomy' => 'product_cat',
                                                        'field' => 'term_id',
                                                        'terms' => $cat->term_id,
                                                        'operator' => 'IN'
                                            ),
                                        )
                                    );

                            $product_querys = new WP_Query($args_query);
                            $product_nums = $product_querys->post_count;

                            if($product_nums > 0){

                                echo do_shortcode('[product_category category="' . esc_attr($cat->slug) . '" per_page=' . esc_attr($product_number) . ' columns=' . esc_attr($column_number) . ' orderby="' . esc_attr(get_option('qcld_orderby_product')) . '" order="' . esc_attr(get_option('order_product_by')) . '"]');

                            }else{
                                echo "<div class='wtcpl_category_empty_msg'> ". esc_html( get_option('qc_woo_tabbed_show_empty_category_msg') ) ." </div>";
                            }
                            ?>
                        </div>
                        <?php $i++;
                    }
                    wp_reset_query();

                    ?>
                </div>
            </div>
            <?php
            return ob_get_clean();
       // }
    }

Code file location:

woo-tabbed-category-product-listing/woo-tabbed-category-product-listing/woo-tabbed-category-product-listing.php

Conclusion

Now that you’ve learned how to embed the Tabbed Category Product Listing for Woocommerce Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *