2015-07-10 14:03
浏览 144


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注册表的人都被分配了用户角色“客户”。 但是,只有具有“雇主”角色的用户实际上才能进行购买...因此,我希望将“我的地址”部分隐藏给“客户”用户。

如果有任何想法, 我可以用函数吗? 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' ) 
    解决 无用
    打赏 举报

相关推荐 更多相似问题