dongtuhe0506
2015-07-10 14:03
浏览 144
已采纳

在WooCommerce我的帐户页面上,根据特定用户角色显示我的地址部分

On the WooCommerce My Account page I am trying to hide a couple of the sections based on the user role.

At the moment, all people who register directly with the WooCommerce registration form are assigned user role 'Customer'. However, only users with role 'Employer' are actually able to make purchases... so effectively I want to hide the My Addresses section to users who are 'Customers'.

Any ideas if I can do this with a function? Miro

图片转代码服务由CSDN问答提供 功能建议

在WooCommerce我的帐户页面上,我试图根据用户角色隐藏几个部分。

目前,所有直接注册WooCommerce注册表的人都被分配了用户角色“客户”。 但是,只有具有“雇主”角色的用户实际上才能进行购买...因此,我希望将“我的地址”部分隐藏给“客户”用户。

如果有任何想法, 我可以用函数吗? Miro

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • doulai8128 2015-07-10 15:52
    最佳回答

    This is possible easily with templates. Add this function in your functions.php file so you can reuse it:

    function isEmployer(){
        $currentUser = wp_get_current_user();
        return in_array('employer', $currentUser->roles);
    }
    

    Grab the my-account.php template from woocommerce > templates > myaccount and copy over to your theme's WooCommerce directory (YOURTHEME > woocommerce > myaccount).

    From there go to line 36. THIS is where the address gets loaded in.

    Wrap the address with a PHP if statement like so:

    <?php if( isEmployer() ){
            wc_get_template( 'myaccount/my-address.php' ) 
        }?>
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题