我们想阻止商店经理更改订单状态,我们在下面的链接中找到了帮助限制用户角色仅更改 Woocommerce 中的某些订单状态 https://stackoverflow.com/questions/54853306/restrict-user-role-to-change-only-some-order-statuses-in-woocommerce
但这里的问题是,它限制了某些角色(店长)对某些订单状态的限制,我们需要完全拒绝店长更改订单状态,而不是限制其对某些订单状态。
此外,我们提到的代码片段从批量操作下拉菜单中删除了订单状态,并在此处删除了订单详细信息:https://prnt.sc/mpfl3b https://prnt.sc/mpfl3b,我们也需要从此处的快速操作列中删除状态https://snipboard.io/B6SYHb.jpg https://snipboard.io/B6SYHb.jpg
简而言之,我们尝试让商店经理在尝试批量更改订单状态、订单详细信息页面或操作列时发现没有订单状态可供选择更改或完全禁用它。
此致
正如您在示例代码中看到的,状态的条件是在 if 语句中确定的,因为您想无限制地应用它,只需删除该 if 语句并返回空数组即可
附注;如果您将我的答案标记为解决方案,那么也投票支持@LoicTheAztec https://stackoverflow.com/users/3730754/loictheaztec如果您还没有这样做,则原始答案,因为他的代码几乎包含了解决方案。
// Admin orders list: bulk order status change dropdown
function filter_dropdown_bulk_actions_shop_order( $actions ) {
// Targeting shop_manager
if( current_user_can( 'shop_manager' ) ) {
$actions = (array) null;
}
return $actions;
}
add_filter( 'bulk_actions-edit-shop_order', 'filter_dropdown_bulk_actions_shop_order', 20, 1 );
// Admin orders list: quick action
function filter_order_actions( $actions, $order ) {
// Targeting shop_manager
if( current_user_can( 'shop_manager' ) ) {
$actions = (array) null;
}
return $actions;
}
add_filter( 'woocommerce_admin_order_actions', 'filter_order_actions', 10, 2 );
// Admin order pages: order status dropdown
function filter_order_statuses( $order_statuses ) {
global $post, $pagenow;
if( $pagenow === 'post.php' || $pagenow === 'post-new.php' ) {
// Get ID
$order_id = $post->ID;
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// TRUE
if ( $order ) {
// Get current order status
$order_status = 'wc-' . $order->get_status();
// New order status
$new_order_statuses = array();
foreach ($order_statuses as $key => $option ) {
// Targeting "shop_manager"
if( current_user_can('shop_manager') && $key == $order_status ) {
$new_order_statuses[$key] = $option;
}
}
if( sizeof($new_order_statuses) > 0 ) {
return $new_order_statuses;
}
}
}
return $order_statuses;
}
add_filter('wc_order_statuses', 'filter_order_statuses', 10, 1 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)