有条件地在Woocommerce管理员订单列表中隐藏特定操作按钮 [英] Hide a specific action button conditionally in Woocommerce admin Orders list
问题描述
我想在订单管理页面中添加一些CSS以隐藏自定义的订单操作按钮,但前提是该订单仅包含可下载的产品。
I Would like to add some CSS to the order admin page to hide a custom order action button, but only if the order contains only downloadable products.
这是我需要有条件加载的功能:
This is the function I need to load conditionally:
add_action( 'admin_head', 'hide_custom_order_status_dispatch_icon' );
function hide_custom_order_status_dispatch_icon() {
echo '<style>.widefat .column-order_actions a.dispatch { display: none; }</style>';
}
有可能吗?
推荐答案
使用CSS,不可能。
相反,您可以挂钩 woocommerce_admin_order_actions
过滤器挂钩,您将可以在其中检查所有订购商品是否可下载然后删除操作按钮调度 :
Instead you can hook in woocommerce_admin_order_actions
filter hook, where you will be able to check if all order item are downloadable and then remove the action button "dispatch":
add_filter( 'woocommerce_admin_order_actions', 'custom_admin_order_actions', 900, 2 );
function custom_admin_order_actions( $actions, $the_order ){
// If button action "dispatch" doesn't exist we exit
if( ! $actions['dispatch'] ) return $actions;
// Loop through order items
foreach( $the_order->get_items() as $item ){
$product = $item->get_product();
// Check if any product is not downloadable
if( ! $product->is_downloadable() )
return $actions; // Product "not downloadable" Found ==> WE EXIT
}
// If there is only downloadable products, We remove "dispatch" action button
unset($actions['dispatch']);
return $actions;
}
代码位于活动子主题的function.php文件中(或活动主题)。
未经测试,但应该可以正常工作……
This is untested but should work…
您将必须检查
'dispatch'
是否适合此操作按钮……
You will have to check that
'dispatch'
is the correct slug for this action button…
这篇关于有条件地在Woocommerce管理员订单列表中隐藏特定操作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!