Reputation: 87
Is there a plugin or some code that after opening some category and all products are show to show products from other category. Because some category or sub-category have only 2-4 products and I want to fill the page with other category product similar.
Example: Gloves
Glove page title
2-4 products
And then some category Boots with 5-6 products
Thanks!
Upvotes: 0
Views: 56
Reputation:
The simple way to do this may simply be to create multiple categories - eg an "apparel" category and assign it both gloves and boots. The more complicated way might be to use the WP_Query to generate a listing.
$args = array(
'post_type' => 'product',
'posts_per_page' => 9,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'my-glove-category'
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'my-boots-category'
)
)
);
$executedQuery = new WP_Query($args);
if ($executedQuery->have_posts()) {
while ($executedQuery->have_posts()) {
$executedQuery->the_post(); //increment the post pointer, getting us the next post in the list
echo '<h2>' . get_the_title() . '</h2>';
}
}
else {
echo 'No products were found.';
}
This example will grab every product that is either in my-glove-category
or my-boots-category
. If you want to sort by the category, that starts to become a bit tougher.
You can also use product_tag
as a taxonomy for these queries, see the installed taxonomies and post types for WooCommerce.
Upvotes: 1