[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">
    <?php
        $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; ?>

            <h2>Shoes</h2>

                <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>                    

                    </a>

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

                </li>

    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
</ul><!--/.products-->

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

Related Posts

How to link WP Domain Checker Buy Button to Contact Form 7

Is it possible to link WP Domain Checker Buy Button / Purchase Button to Contact Form 7? This is a question from one of WP Domain Checker user. The answer is YES. It is possible! We can use HTTP GET variables feature from Contact Form 7. To get the default value from HTTP GET variables, add default:get option to […]

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