php - 在 Woocommerce 管理订单列表中有条件地隐藏特定操作按钮

标签 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 { 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/

相关文章:

css - 如何将 css 属性添加到 CellTable 的 ImageResourceCell 中的图像

php - 在 Woocommerce 3 中使用 CRUD 方法以编程方式创建产品

javascript - 模板中的 Mustache php 空间

php - MYSQL 对多个表的求和值

html - 在 HTML5 中使用 SVG 文件并改变颜色

表单内的 HTML 标签和输入框不对齐

wordpress - 如何在管理员内显示附加到帖子的图像?

javascript - 如何在正文末尾的 ELEMENTOR 脚本之后加载我的脚本

php - Tinymce,禁用 numlist 下拉列表

php - 使用 Left Join 优化 Mysql 查询 Group_concat