WooCommerce – Show different terms and conditions for different user roles

The Wholesale role was created as part of a plugin that’s been installed (WooCommerce Wholesale Pro Suite). Currently, the T&C link is being displayed using the standard WooCommerce functionality.

But what I’ve done is amend the terms.php file, within the checkout folder of the WooCommerce templates (copying it to my theme folder) and I’ve found a function that will check if a user has a particular role – so I’m just doing a simple if statement to display a different T&C’s link if the user has the wholesale role.

This is the code I’ve used:

// flag to indicate if the user is not assigned the wholesale user role
$wholesale_user_role = 0;
// get the roles of the currently logged in user
if ($user_id) $user = get_userdata($user_id);
else $user = wp_get_current_user();
    if (empty($user)) return false;
        // loop through each of the roles
        foreach ($user->roles as $role) {
            // check to see if the user has been assigned the wholesale user role
                if (in_array($role, array('ignite_level_5aedba974920a'))) {
                // current logged in user is assigned the wholesale user role, so set the flag to 1 (true)
                    $wholesale_user_role = 1;
                }
            }
            // check to see if the currently logged in user has the wholesale user role 
            if(!$wholesale_user_role) {
                // isn't assigned the wholesale user role, so display the standard t&c's text and link
            ?>
                <span class="woocommerce-terms-and-conditions-checkbox-text"><?php wc_terms_and_conditions_checkbox_text(); ?></span>&nbsp;<span class="required">*</span>
            <?php
            } else { 
            // current user is assigned the wholesale role, so display wholesale T&C's ?>
                <span class="woocommerce-terms-and-conditions-checkbox-text">I have read and agree to the website <a href="https://www.example.com/wholesale/wholesale-terms-conditions/" class="woocommerce-terms-and-conditions-link" target="_blank">terms and conditions</a></span>&nbsp;<span class="required">*</span>
            <?php
            }
            ?>

Not sure if it’s the best way but is working for me.