Posted on

How to enable quote request only to selected roles in WooCommerce.

The following setup enables you to enable quote request checkout only to selected roles and allow others to buy and checkout normally.

If you need help setting it up, we can help.

Set the default setting to RFQ.

cid:image001.png@01D64977.7C2EDC30

In the roles, leave 4a blank and in 4b add the role(s) that can only request a quote. You have to create the role first.

cid:image002.png@01D64978.B1C46670

At the very bottom of the page, enter a label for people who can purchase(everybody else). This

Is the label for the cart button .

cid:image003.png@01D64978.B1C46670

In the labels section use “Add to Quote”

cid:image004.png@01D64978.B1C46670

And finally add this to the bottom of your functions.php

if(function_exists('gpls_woo_rfq_purchase_only')) {

    add_action('init', 'gpls_woo_rfq_check_role', 1);

    function gpls_woo_rfq_check_role()
    {
        $in_role = false;

        if (is_user_logged_in())
        {

            $user = wp_get_current_user();

            $user_roles = $user->roles;

            $eligible_roles = get_option('settings_gpls_woo_rfq_plus_visible_price_roles', 'no');

            $option_value_list = explode(',', $eligible_roles);

            foreach ($user_roles as $cat_id) {

                if (in_array(trim($cat_id), $option_value_list)) {
                    $in_role = true;
                }
            }
        }

        if($in_role == false){
            gpls_woo_rfq_purchase_only(); // user can see prices and purchase normally
        }


    }

}