Okay
  Public Ticket #2845444
Filtering group prices with meta_query
Closed

Comments

  •  8
    Martin Stolk started the conversation

    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?


  •  2,217
    WebWizards replied

    Hi 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,

    Stefan

  •  8
    Martin Stolk replied

    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.