Php 在管理命令列表中有条件地隐藏特定操作按钮
我想添加一些CSS到订单管理页面,以隐藏自定义订单操作按钮,但前提是订单只包含可下载的产品 这是我需要有条件加载的函数:Php 在管理命令列表中有条件地隐藏特定操作按钮,php,css,wordpress,woocommerce,orders,Php,Css,Wordpress,Woocommerce,Orders,我想添加一些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 {
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\u admin\u order\u actions过滤器钩子,在该钩子中,您可以检查所有订单项目是否都可下载,然后删除操作按钮dispatch:
代码进入活动子主题或活动主题的function.php文件
这是未经测试,但应工作
您必须检查“dispatch”是否是此操作按钮的正确slug
谢谢你在这里帮助我,它工作得很好。
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;
}