我想向订单管理页面添加一些 CSS 以隐藏自定义订单操作按钮,但前提是订单仅包含可下载的产品。
这是我需要有条件地加载的函数:
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 不可能。
相反,您可以 Hook woocommerce_admin_order_actions
过滤器 Hook ,您可以在其中检查是否所有订单商品都可以下载,然后删除操作按钮 “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 文件。
这是未经测试的,但应该可以工作......
You will have to check that
'dispatch'
is the correct slug for this action button…
关于php - 在 Woocommerce 管理订单列表中有条件地隐藏特定操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48399729/