批发角色是作为已安装插件的一部分创建的(WooCommerce批发Pro套件)。目前;使用标准WooCommerce功能显示C链接。
但我所做的是修改条款。php文件,在WooCommerce模板的checkout文件夹中(将其复制到我的主题文件夹),我发现了一个函数,可以检查用户是否具有特定角色,因此我只需执行一个简单的if语句来显示不同的T&;如果用户具有批发角色,则为C的链接。
这是我使用的代码:
// 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> <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> <span class="required">*</span>
<?php
}
?>
不确定这是否是最好的方式,但对我来说是有效的。