Public Ticket #2854640

Meta_query: remove products (in categories) set invisible to current user

Closed
Comments
9 Tickets 8
Martin Stolk started the conversation 5 years ago on August 22, 2021 at 11:44am

Whereas the normal shop pages filter correctly, I'm working with a plugin (Woo Product table). it still shows products and product categories that are set invisible to the group/user by B2B-king. This is why I want to make the selecting query compatible with the B2B visibility feature.

Can you please assist me by implementing this selection query which:

Only selects products which are 

1. are set visible to the current B2BKing user (on a product level)

2. are within a category which is visible to the current B2BKing user

It probably looks something like this:

if ($b2b_king_user) {
   //filter out categories invisible to user or user's group (set in category)
   $args['tax_query']['product_cat_invisible'] = array(  
      'taxonomy' => 'product_cat',
      'field' => 'id',
      'terms' => $cat_ids_hidden_to_current_user,
      'operator' => 'NOT IN'
   );

   //filter out products invisible to user or user's group (set in product)
   $args['post__not_in'] = $product_ids_hidden_to_current_user;
}


2,762
KingsPlugins replied 5 years ago on August 23, 2021 at 10:17pm

Hi Martin, 

Some thoughts on that:

1. Our plugin has a setting in B2BKing -> Settings -> Other -> Product Visibility Cache, that users "pre_get_posts" to set visibility as well. Please try to enable that setting, as perhaps it can resolve your issue without additional work.


2. 

You could use the following:

$visible_ids = get_transient('b2bking_user_'.get_current_user_id().'_ajax_visibility');

The above gets an array of all visible product IDs for the current user. You could set post__in to the above array.

So I think all that would be necessary is to add

$args['post__in'] = $visible_ids;


Hope that helps. Let me know,

Kind regards,

Stefan

1
9 Tickets 8
Martin Stolk replied 5 years ago on August 24, 2021 at 9:38am

Hi Stefan,

The first option (Product Visibility Cache) already was enabled by me, to correct the behavior of our WPML-enabled site. The standard Woocommerce Carousel was fixed by this.

Today I've fixed the plugin by your second suggestion. It seems to work flawlessly by performing an array intersection with the $visible_ids of your reply.

Thank you (again) for your great support.

Kind regards,
Martin

1
9 Tickets 8
Martin Stolk replied 5 years ago on September 21, 2021 at 3:37pm

Hello Elvedin,

Of course, here is my modified shortcode.php file.
Place it in the following location: /public_html/wp-content/plugins/woo-product-table/includes/shortcode.php

If it works well for you (please test it thoroughly) than I will create a pull request to the author of the Woo Product Table plugin, so hopefully it will be integrated in one of the future releases by default.

Kind regards,
Martin


2 Tickets 1
Elvedin Kurtovic replied 5 years ago on September 21, 2021 at 3:48pm

Thank you so much but upon inspecting the root where i need to place this, the plugin is different. mine is called woocommerce product table, i do not have folder woo-product table. only this woocommerce-product-table

9 Tickets 8
Martin Stolk replied 5 years ago on September 21, 2021 at 3:56pm

Hello Elvedin,

Of course, here is my modified shortcode.php file. Place it in the following location: /public_html/wp-content/plugins/woo-product-table/includes/shortcode.php

If it works well for you (please test it thoroughly) than I will create a pull request to the author of the Woo Product Table plugin, so hopefully it will be integrated in one of the future releases by default.

Kind regards,
Martin

Sign In