admin管理员组文章数量:1323330
I am running the following snippet on my wordpress site to display an image. I would like to hide this div if the user role is "wholesale" (a custom role I created). Is this possible?
add_action( 'woocommerce_review_order_after_submit', 'content_below_checkout_button' );
function content_below_checkout_button() {
echo '<div style="text-align: center"><img style="margin-top:20px; display:inline-block;" src="/uploads/2020/07/image.png'.$photo->name.'"/></div>';
}
I am running the following snippet on my wordpress site to display an image. I would like to hide this div if the user role is "wholesale" (a custom role I created). Is this possible?
add_action( 'woocommerce_review_order_after_submit', 'content_below_checkout_button' );
function content_below_checkout_button() {
echo '<div style="text-align: center"><img style="margin-top:20px; display:inline-block;" src="/uploads/2020/07/image.png'.$photo->name.'"/></div>';
}
Share
Improve this question
asked Sep 3, 2020 at 6:32
zzzlucidzzzlucid
112 bronze badges
1 Answer
Reset to default 0Basically, just check inside the action if an array of the current user's roles contains the wholesale
role.
function content_below_checkout_button() {
if ( in_array( 'wholesale', wp_get_current_user()->roles ) ) {
echo '<div style="text-align: center"><img style="margin-top:20px; display:inline-block;" src="/uploads/2020/07/image.png'.$photo->name.'"/></div>';
}
}
add_action( 'woocommerce_review_order_after_submit', 'content_below_checkout_button' );
I'm not sure what's going on with the rest of your code, but I assume it was working.
本文标签: phpHiding div based on user role
版权声明:本文标题:php - Hiding div based on user role 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742140223a2422548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论