Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1290935
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionI have a snippet of code that allows me to hide the order notes field at checkout for all users (logged in or not) but wanted to ask if someone has written a snippet that hides the same field from everyone, except Administrators.
Essentially, I want site administrator-level users to be able to add order notes when checking out, but no one else.
The current snippet is:
// Removes Order Notes Title - Additional Information & Notes Field
add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );
// Remove Order Notes Field
add_filter( 'woocommerce_checkout_fields' , 'remove_order_notes' );
function remove_order_notes( $fields ) {
unset($fields['order']['order_comments']);
return $fields;
}
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionI have a snippet of code that allows me to hide the order notes field at checkout for all users (logged in or not) but wanted to ask if someone has written a snippet that hides the same field from everyone, except Administrators.
Essentially, I want site administrator-level users to be able to add order notes when checking out, but no one else.
The current snippet is:
// Removes Order Notes Title - Additional Information & Notes Field
add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );
// Remove Order Notes Field
add_filter( 'woocommerce_checkout_fields' , 'remove_order_notes' );
function remove_order_notes( $fields ) {
unset($fields['order']['order_comments']);
return $fields;
}
Share
Improve this question
edited Jun 9, 2021 at 15:35
Jacob Peattie
44.1k10 gold badges50 silver badges64 bronze badges
asked Jun 9, 2021 at 15:17
Joey PayneJoey Payne
1
1 Answer
Reset to default 1You could add an admin check with current_user_can()
, something like this
function remove_order_notes( $fields ) {
if (current_user_can('administrator')) return $fields;
unset($fields['order']['order_comments']);
return $fields;
}
If the current user is admin, return all fields.
版权声明:本文标题:code - Make order notes field at woocommerce checkout only viewable on front end by Admin level user role 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741514389a2382796.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论