限制用户角色仅更改 Woocommerce 中的某些订单状态
Restrict user role to change only some order statuses in Woocommerce
我想限制角色对 woocommerce 下拉列表中某些订单状态的访问。我已经在 functions.php 子主题中尝试了 Restrict woocommerce order status by role 上的代码,但无法使其正常工作并且没有足够的代表来 post 发表评论。
https://prnt.sc/mpfl3b 是所显示内容的屏幕截图 - 我希望商店经理(或创建的自定义角色)只能将订单标记为正在处理或暂停,而没有其他选项可见下拉菜单。
如有任何建议,我们将不胜感激。
链接的答案代码不适用于您想要的。请尝试以下操作:
// Admin orders list: bulk order status change dropdown
add_filter( 'bulk_actions-edit-shop_order', 'filter_dropdown_bulk_actions_shop_order', 20, 1 );
function filter_dropdown_bulk_actions_shop_order( $actions ) {
$new_actions = [];
foreach( $actions as $key => $option ){
// Targeting "shop_manager" | order statuses "on-hold" and "processing"
if( current_user_can('shop_manager') && in_array( $key, array('mark_on-hold', 'mark_processing') ) ){
$new_actions[$key] = $option;
}
}
if( sizeof($new_actions) > 0 ) {
return $new_actions;
}
return $actions;
}
// Admin order pages: Order status change dropdown
add_filter('wc_order_statuses', 'filter_order_statuses');
function filter_order_statuses($order_statuses) {
global $pagenow;
if( $pagenow === 'post.php' || $pagenow === 'post-new.php' ) {
$new_order_statuses = array();
foreach ($order_statuses as $key => $option ) {
// Targeting "shop_manager" | order statuses "on-hold" and "processing"
if( current_user_can('shop_manager') && in_array( $key, array('wc-on-hold', 'wc-processing') ) ){
$new_order_statuses[$key] = $option;
}
}
if( sizeof($new_order_statuses) > 0 ) {
return $new_order_statuses;
}
}
return $order_statuses;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。它应该有效。
我想限制角色对 woocommerce 下拉列表中某些订单状态的访问。我已经在 functions.php 子主题中尝试了 Restrict woocommerce order status by role 上的代码,但无法使其正常工作并且没有足够的代表来 post 发表评论。
https://prnt.sc/mpfl3b 是所显示内容的屏幕截图 - 我希望商店经理(或创建的自定义角色)只能将订单标记为正在处理或暂停,而没有其他选项可见下拉菜单。
如有任何建议,我们将不胜感激。
链接的答案代码不适用于您想要的。请尝试以下操作:
// Admin orders list: bulk order status change dropdown
add_filter( 'bulk_actions-edit-shop_order', 'filter_dropdown_bulk_actions_shop_order', 20, 1 );
function filter_dropdown_bulk_actions_shop_order( $actions ) {
$new_actions = [];
foreach( $actions as $key => $option ){
// Targeting "shop_manager" | order statuses "on-hold" and "processing"
if( current_user_can('shop_manager') && in_array( $key, array('mark_on-hold', 'mark_processing') ) ){
$new_actions[$key] = $option;
}
}
if( sizeof($new_actions) > 0 ) {
return $new_actions;
}
return $actions;
}
// Admin order pages: Order status change dropdown
add_filter('wc_order_statuses', 'filter_order_statuses');
function filter_order_statuses($order_statuses) {
global $pagenow;
if( $pagenow === 'post.php' || $pagenow === 'post-new.php' ) {
$new_order_statuses = array();
foreach ($order_statuses as $key => $option ) {
// Targeting "shop_manager" | order statuses "on-hold" and "processing"
if( current_user_can('shop_manager') && in_array( $key, array('wc-on-hold', 'wc-processing') ) ){
$new_order_statuses[$key] = $option;
}
}
if( sizeof($new_order_statuses) > 0 ) {
return $new_order_statuses;
}
}
return $order_statuses;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。它应该有效。