Product Visibility Compatibility

Below are some PHP snippets + guides to make B2BKing product visibility compatible with 3rd party plugins.

Here is a guide for adding PHP snippets: Add PHP/JS Snippets

Barn2 WooCommerce Product Table #

To make B2BKing's visibility work with this table plugin:

  • Make sure to disable the Product Table Cache in their plugin's settings:
6531233623.png
Caching should be DISABLED
  • Add the following PHP snippet
add_filter( 'wc_product_table_query_args', function( $args, $table_query ) {
    // do something with $args
    if (isset($args['post__in'])){
	$currentval = $args['post__in'];
    } else {
    	$currentval = array();
    }
    
    $allTheIDs = get_transient('b2bking_user_'.get_current_user_id().'_ajax_visibility');
    $allTheIDs = apply_filters('b2bking_ids_post_in_visibility', $allTheIDs);

    if (empty($allTheIDs)){
        $allTheIDs = array('invalid');
    }

    $args['post__in'] = $allTheIDs;
    
    if (!empty($currentval)){
        $allTheIDs = array_intersect($allTheIDs, $currentval);
    }
    
    return $args;
}, 10, 2 );
  • It is recommended to enable the B2BKing visibility cache in B2BKing -> Settings -> Other -> Product Visibility Cache.

Powered by BetterDocs