How to exclude categories in WooCommerce Wholesale Pro

Barn2’s WooCommerce Wholesale Pro plugin offers a robust solution for businesses looking to set up a wholesale store within their WooCommerce-powered website. One common customization that users may seek is the ability to exclude certain product categories from the wholesale store page while keeping them visible to wholesale users. In this article, we’ll explore a simple and effective way to achieve this customization using a piece of PHP code.

To exclude specific categories from the wholesale store page, we can leverage the flexibility of the plugin’s hooks and filters. The provided PHP code snippet serves as a valuable tool to modify the default behavior of the plugin, allowing users to tailor their wholesale store to meet their specific needs.

Here’s a breakdown of the PHP code and how to implement it:

function exclude_category_from_archive( $tax_query ) {
    $tax_query[] = [
        'taxonomy'         => 'product_cat',
        'field'            => 'term_id',
        'terms'            => [ 26, 61 ],  // Replace these term IDs with the ones you want to exclude
        'include_children' => true,
        'operator'         => 'NOT IN',
    ];

    return $tax_query;
}
add_filter( 'wcwp_store_query_tax_query', 'exclude_category_from_archive' );

Let’s break down the key components of this code:

  1. Function Name: exclude_category_from_archive is a user-defined function responsible for modifying the tax query used in the wholesale store page.
  2. Tax Query Parameters:
  • taxonomy: Specifies the taxonomy to query, which, in this case, is ‘product_cat’ for product categories.
  • field: Sets the field to ‘term_id’ for term identification.
  • terms: An array of term IDs that should be excluded. Replace the sample term IDs (26, 61) with the actual IDs of the categories you want to exclude.
  • include_children: Indicates whether to include child terms of the specified categories.
  • operator: Sets the comparison operator to ‘NOT IN’ for exclusion.
  1. Hook: The add_filter function hooks into the ‘wcwp_store_query_tax_query’ filter provided by the WooCommerce Wholesale Pro Plugin. It tells WordPress to apply our custom function (exclude_category_from_archive) to modify the tax query when generating the wholesale store page.

To implement this code, you can add it to your child theme’s functions file or use a code snippets plugin such as “Insert Headers and Footers.” Simply copy and paste the code into the appropriate file or plugin, replacing the term IDs as needed.

This customization empowers users to fine-tune their wholesale store, excluding specific categories from the default display while ensuring they remain accessible to wholesale users. With the flexibility provided by this PHP code snippet, businesses can create a tailored wholesale experience that aligns seamlessly with their unique product offerings.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top