You can use the shortcode [products_by_category_slug product_cat=”category-slug” orderby=”rand”] by adding the below conde in theme function.php file.
<?php
add_shortcode( ‘products_by_category_slug’, ‘products_by_category_slug’ );
function products_by_category_slug( $atts, $content = null ) {
extract( shortcode_atts( array(
‘product_cat’ => ”,
‘orderby’ => ‘rand’,
), $atts));
?>
<ul class=”products”>
<?php
$args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ‘product_cat’ =>$product_cat, ‘orderby’ => $orderby);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class=”product”>
post->ID ) ?>” title=”<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>”>
<h3><?php the_title(); ?></h3>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php
}
?>