0

I'm setting up a WooCommerce shop and it will have two types of customer/user roles - a standard retail customer/user role and a wholesale customer/user role.

Here's the snag that I've hit - when a Wholesale customer is logged in, I need the Terms and Conditions link on the checkout page to go to a different T&C's page.

I've tried a couple of different functions in functions.php to replace the link text but they don't work.

Does anyone out there have any suggestions that I can try??

Thanks,

Bev

3
  • Did you create the new role with add_role()? How are you displaying the T&C link? – RiddleMeThis Jun 24 '19 at 17:22
  • @RiddleMeThis The Wholesale role is 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 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. Not sure if it's the best way but is working for me. – ThinkLoveDigital Jun 26 '19 at 11:06
  • You should post your solution as an answer and accept it. – RiddleMeThis Jun 26 '19 at 13:22
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.