In most WordPress sites the Shop page displays all the products by default. If you are looking to limit the products to only those from specified product categories, simply add the following code snippet.

add_action( 'woocommerce_product_query', 'wpdd_limit_shop_categories' );
/**
 * Show products from specific product categories on the Shop page.
 */
function wpdd_limit_shop_categories( $q ) {
    $tax_query = (array) $q->get( 'tax_query' );

    $tax_query[] = array(
		'taxonomy' => 'product_cat',
		'field' => 'slug',
		'terms' => array( 'decor', 'music' ),
		'include_children' => true,
    );

    $q->set( 'tax_query', $tax_query );
}

Specify the slugs of product categories you want to show from in

'terms' => array( 'decor', 'music' ),

To show them from a single product category, of say accessories, you would change the above line to:

'terms' => array( 'accessories' ),

Note that any products in child (sub) categories of the specific category/categories will also be included.

If you do not want the products from sub categories to be shown, change

'include_children' => true,

to

'include_children' => false,

Before:

After:

where

If you are using Oxygen here's how you set up the Shop page:

  1. Install and activate Oxygen Elements for WooCommerce plugin.
  2. Create a Template named say, Shop. Set it to inherit the design from your Main Catch All Template. Set the Template to apply to product post type's archive.
  3. Edit with Oxygen.
  4. Add a Section and inside that add Products List component.
  5. Save.

References

https://github.com/luetkemj/wp-query-ref

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE

Comments

You need to be logged in to view and post comments.
Not a member yet? Join here.
magnifiercross
>
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: