Home / eCommerce / Fix Wholesale Product Visibility Compatibility with Bricks Page Builder
Duplicate Snippet

Embed Snippet on Your Site

Fix Wholesale Product Visibility Compatibility with Bricks Page Builder

What this does:
- Bricks Products widget now gets its product list filtered through WWPP_Query::pre_get_posts_arg, the same method WWPP uses for WooCommerce widgets/shortcodes.
- Any product restricted to a specific wholesale role (e.g. “wholesale B”) will no longer be visible to guests/retail users in Bricks product archives.
- No extra config needed: it fully respects your existing WWPP “Only show wholesale products to wholesale users” and per‑product visibility settings.

Code Preview
php
<?php
/**
 * 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
);

Comments

Add a Comment