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; }
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.
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.
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.
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
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.
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;
}
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:
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
Hope that helps. Let me know,
Kind regards,
Stefan
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
Hey Martin,
Glad that worked! Happy to help
Can you help out, where exactly did you use this code, because i have the same issue like you did.
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
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
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
That is probably a different plugin indeed. The modified file is for this plugin:
https://nl.wordpress.org/plugins/woo-product-table/