SOLVED: Product Visibility issue - Wholesale Suite Plugin (Products element)

Hi,

We have discovered an incompatibility issue with Bricks Builder and the Wholesale Suite plugin (https://wholesalesuiteplugin.com/) where products that are restricted to be visible to wholesale roles are still visible and are listed in Bricks archive templates.

When clicking the product link, we are redirected to the shop page instead of being shown the product page, but we can still add the product to our cart from the listing/archive pages. The products should not be visible at all in the archive/list of products.

We know it’s a compatibility issue with Bricks and Wholesale Suite, because if we install the WooCommerce StoreFront theme, the issue is no longer present and the products that are restricted to wholesale roles are not visible to anyone but customers logged in with those roles.

In Bricks Builder, I am using the default Product element to list products, with no major changes to the query except for 32 products per page and sorting by menu order.

Bricks, Woo and all plugins and core are up to date.

Hi Jimmy,
Thanks so much for your report!

I am not familiar with the plugin, so it is possible that there is an incompatibility. However, I cannot test this myself, as product visibility is a premium feature and we do not currently have a license for this plugin.

Accordingly, it would be great if you could provide us with login credentials to a staging environment (help@bricksbuilder.io with a link to this thread using the email address associated with your account), so we can check what’s going on.

Best regards,
timmse

Hi timmse,

Thanks so much for your response. I’ve sent an email to help@bricksbuilder.io with a video demo of the issue and staging logins.

I believe it’s an issue with the way Bricks or the product element specifically is hooking into the core woocommerce loop for displaying products, and is missing something. I’m by no means an expert on these things, so looking forward to you guys looking into it and hopefully a resolution.

Many thanks

Just a quick update. I have been working with your team - who are great by the way! - and the bug was located in the product element. There was no issue when using Custom Query loop. Bricks team has offered to implement a fix.

Wholesale Suite Plugin support also came to the party and provided a code snippet fix so that the Bricks Products widget now filters products using WWPP_Query::pre_get_posts_arg, which is the same method Wholesale Suite uses for WooCommerce widgets and shortcodes.

Hopefully the bug fix for the Products element will be rolled out in an update. Kudos to both teams for being responsive, great to deal with and both resolving the issue.

1 Like

We fixed this issue in Bricks 2.2 RC, now available as a manual download in your account (see changelog).

Please let us know if you are still experiencing issues.

As with any pre-stable release, please do not use it on a production website. It is intended for testing in a local or staging environment only.

Hi @timmse ,

We disabled the code snippet provided by the wholesale suite team. However, we found the issue still present in the search results template for bricks. The product element has “main query” enabled, yet products that are restricted to specific roles are still showing up in search results. I enabled the snippet provided by the wholesale suite team and it fixed the issue, but it seems perhaps there is still something missing in bricks with regards to search queries?

Here’s the snippet that fixes the issue:

/**

  • Make Bricks product queries (Products element) respect
  • WooCommerce Wholesale Prices Premium product visibility.
    */

add_filter(
‘bricks/posts/query_vars’,
function ( $query_vars, $settings, $element_id, $element_name ) {
// Only affect product queries
$post_type = $query_vars[‘post_type’] ?? null;
$is_product_query =
( is_string( $post_type ) && ‘product’ === $post_type ) ||
( is_array( $post_type ) && in_array( ‘product’, $post_type, true ) );

    if ( ! $is_product_query ) {
        return $query_vars;
    }

    // Ensure WWPP is available
    global $wc_wholesale_prices_premium;
    if (
        ! isset( $wc_wholesale_prices_premium ) ||
        ! isset( $wc_wholesale_prices_premium->wwpp_query )
    ) {
        return $query_vars;
    }

    // Let WWPP apply its standard wholesale visibility logic
    // (same as for WC widgets & shortcodes)
    $query_vars = $wc_wholesale_prices_premium->wwpp_query->pre_get_posts_arg( $query_vars );

    return $query_vars;
},
20,
4

);

Hi Jimmy,
Please send us the login credentials again (ideally for the staging environment) so our developers can take a look at it :v: