Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

WooCommerce products from multiple taxonomies

WooCommerce products from multiple taxonomies

// WP_Query arguments
$args = array(
	'post_type'              => array( 'product' ),
	'post_status'            => array( 'publish' ),
	'posts_per_page'         => '-1',
	'order'                  => 'ASC',
	'orderby'                => 'date',
	'tax_query'              => array(
		'relation' => 'AND',
		array(
			'taxonomy'         => 'product_cat',
			'terms'            => '666',
			'field'            => 'term_id',
			'operator'         => 'IN',
			'include_children' => false,
		),
		array(
			'taxonomy'         => 'product_brand',
			'terms'            => '666',
			'field'            => 'term_id',
			'operator'         => 'IN',
			'include_children' => false,
		),
	),
);

// The Query
$products_from_multiple_taxonomies = new WP_Query( $args );

// The Loop
if ( $products_from_multiple_taxonomies->have_posts() ) {
	while ( $products_from_multiple_taxonomies->have_posts() ) {
		$products_from_multiple_taxonomies->the_post();
		// do something
	}
} else {
	// no posts found
}

// Restore original Post Data
wp_reset_postdata();