Comments 8Martin Stolk started the conversationAugust 9, 2021 at 9:28pmI have a plugin that lists all products in a convenient product table and would like to show only the products that do have a set price (>0) for the logged in user (as part of a B2B group).The plugin filters using this meta_query code:$args['meta_query'][] = array( 'key' => '_price', 'value' => $min_price, 'compare' => '>=', 'type' => 'NUMERIC' );But the effect is filtering on the standard user's price instead of the price for the B2B group of that user.Can you advise me how to adjust the meta_query so it filters on the current user's B2B-king price instead? 2,217WebWizards repliedAugust 9, 2021 at 11:43pmHi Martin,Based on the meta_query code you posted, I think this is the code you would need: $user_id = get_current_user_id(); $is_b2b = get_user_meta($user_id, 'b2bking_b2buser', true); if ($is_b2b === 'yes'){ $user_group = get_user_meta($user_id, 'b2bking_customergroup', true); $args['meta_query'][] = array( 'key' => 'b2bking_regular_product_price_group_'.$user_group, 'value' => $min_price, 'compare' => '>=', 'type' => 'NUMERIC' ); } else { // user is b2c } The above code gets the current user's group and sets that meta query based on the group price.Kind regards,Stefan1 Like 8Martin Stolk repliedAugust 10, 2021 at 6:51amFabulous! This does exactly what I want.I will propose a pull request to the plugin's author as well.Thank you for your help.1 Like Sign in to reply ...
I have a plugin that lists all products in a convenient product table and would like to show only the products that do have a set price (>0) for the logged in user (as part of a B2B group).
The plugin filters using this meta_query code:
$args['meta_query'][] = array(
'key' => '_price',
'value' => $min_price,
'compare' => '>=',
'type' => 'NUMERIC'
);
But the effect is filtering on the standard user's price instead of the price for the B2B group of that user.
Can you advise me how to adjust the meta_query so it filters on the current user's B2B-king price instead?
Hi Martin,
Based on the meta_query code you posted, I think this is the code you would need:
The above code gets the current user's group and sets that meta query based on the group price.
Kind regards,
Stefan
Fabulous! This does exactly what I want.
I will propose a pull request to the plugin's author as well.
Thank you for your help.