在WooCommerce我的帐户页面上,我试图根据用户角色隐藏几个部分。
目前,所有直接注册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
最满意答案
使用模板可以轻松实现这一点。 在functions.php文件中添加此函数,以便重用它:
function isEmployer(){ $currentUser = wp_get_current_user(); return in_array('employer', $currentUser->roles); }从woocommerce > templates > myaccount my-account.php模板,然后将其复制到主题的WooCommerce目录( YOURTHEME > woocommerce > myaccount )。
从那里到第36行。这是地址加载的地方。
用PHP if语句包装地址,如下所示:
<?php if( isEmployer() ){ wc_get_template( 'myaccount/my-address.php' ) }?>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' ) }?>更多推荐
发布评论