在WooCommerce我的帐户页面上,根据特定用户角色显示我的地址部分(On WooCommerce My account page, display My Addresses section ba

编程入门 行业动态 更新时间:2024-10-19 02:26:09
在WooCommerce我的帐户页面上,根据特定用户角色显示我的地址部分(On WooCommerce My account page, display My Addresses section based on specific user role)

在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' ) }?>

更多推荐

本文发布于:2023-08-04 10:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415200.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:帐户   角色   页面   地址   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!