[Woocommerce] How to Display Products from Specific Category

These code to show product with ‘shoe’ category.
You can change ‘shoe’ with any category you want.

‘orderby’ => ‘rand’ mean show the product as random.

orderby (string | array) – Sort retrieved posts by parameter. Defaults to ‘date (post_date)’. One or more options can be passed.
‘none’ – No order (available since Version 2.8).
‘ID’ – Order by post id. Note the capitalization.
‘author’ – Order by author. (‘post_author’ is also accepted.)
‘title’ – Order by title. (‘post_title’ is also accepted.)
‘name’ – Order by post name (post slug). (‘post_name’ is also accepted.)
‘type’ – Order by post type (available since Version 4.0). (‘post_type’ is also accepted.)
‘date’ – Order by date. (‘post_date’ is also accepted.)
‘modified’ – Order by last modified date. (‘post_modified’ is also accepted.)
‘parent’ – Order by post/page parent id. (‘post_parent’ is also accepted.)
‘rand’ – Random order. You can also use ‘RAND(x)’ where ‘x’ is an integer seed value.

<ul class="products">
        $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'shoes', 'orderby' => 'rand' );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>


                <li class="product">    

                    <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">

                        <?php woocommerce_show_product_sale_flash( $post, $product ); ?>

                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>

                        <h3><?php the_title(); ?></h3>

                        <span class="price"><?php echo $product->get_price_html(); ?></span>                    


                    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>


    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

Ref: https://wordpress.stackexchange.com/questions/67247/how-to-display-product-specific-to-a-category-with-woocommerce-plugin

Related Posts


August 8, 2017

Security, WordPress

Recently I’ve been contacted by several clients reporting malware on their WordPress sites which redirects pages and post to other websites like http://traffictrade.life. It is affecting pretty much all the posts and pages of the site. They’re simply looking for “<a href” which is code they know will be present in virtually every post on […]

Read More

Recommended File Permissions for WordPress

July 31, 2017

Security, Tutorial, WordPress

What permissions should I have for the following: Root folder storing all the WordPress content wp-admin wp-content wp-includes On computer filesystems, different files and directories have permissions that specify who and what can read, write, modify and access them. This is important because WordPress may need access to write to files in your wp-content directory to enable certain functions. […]

Read More