Listing WooCommerce products by tags

Listing WooCommerce products by tags

This may not be a frequent request, but few months ago I had a client who wanted to list WooCommerce products by tags assigned to each product. There was no official plugin available (there still isn’t, from what I can tell), but a quick googling brought me to solution created by Remi Corson, WooThemes developer. The solution is very simple, it is actually a shortcode, and below you will find my forked version in which I only added few more shortcode parameters. You can download it from Gist, or you can download the zip file file below the code and install it into your website as a regular plugin. Copyrights go to plugin author.

 '12',
			'columns' 		=> '4',
			'orderby'   	=> 'title',
			'order'     	=> 'desc',
			'category'		=> '',
			'tags'          => '',
					), $atts ) );
	
	ob_start();
	// Define Query Arguments
	$args = array(
			'post_type'				=> 'product',
			'post_status' 			=> 'publish',
			'ignore_sticky_posts'	=> 1,
			'orderby' 				=> $ordering_args['orderby'],
			'order' 				=> $ordering_args['order'],
			'posts_per_page' 		=> $per_page,
			'product_tag'           => $tags, 
		'tax_query' 			=> array(
				array(
					'taxonomy' 		=> 'product_cat',
					'terms' 		=> array( esc_attr( $category ) ),
					'field' 		=> 'slug',
					'operator' 		=> $operator
					
				))
		);
	
ob_start();
		$products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
		$woocommerce_loop['columns'] = $columns;
		if ( $products->have_posts() ) : ?>

			

				have_posts() ) : $products->the_post(); ?>

					

				

			

		' . ob_get_clean() . '
'; } add_shortcode("woo_products_by_tags", "woo_products_by_tags_shortcode");

Download plugin.