删除 Woocommerce 管理员订单列表中的下拉 select 字段过滤器

Remove a dropdown select field filter in Woocommerce admin orders list

在 WooCommerce 3.0+ 版本中,我想删除 Woocommerce 订单面板上的所有送货国家过滤器。

怎么做?有什么想法吗?

谢谢

我使用 css 删除了我在 function.php 中添加了此功能

add_action('admin_head', 'hidey_admin_head');
function hidey_admin_head() {
    echo '<style type="text/css">';
    echo 'select[name=_customer_shipping_country] {display: none;}';
    echo '</style>';
}

This selectors you want to remove are custom and certainly added by a third party plugin.

您可以尝试使用挂接到 admin_head 操作挂钩的自定义函数来隐藏下拉选择器字段。您需要将 CSS ID #my_selector_id 替换为要隐藏的选择器的 ID 或 class (使用浏览器代码检查器找到正确的选择器)

add_action( 'admin_head', 'adding_custom_css_in_admin_head', 999 );
function adding_custom_css_in_admin_head() {
    ?>
        <style type="text/css">
            body.post-type-shop_order select#my_selector_id {
                display: none !important;
            }
        </style>
    <?php
}

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。

此代码已经过测试,它应该适用于您的下拉选择器字段。

selected 的答案不是最佳解决方案,因为过滤器仍在创建中,它们只是被隐藏了。相反,您应该挂钩正确的过滤器并阻止 WooCommerce 插件创建 select 框:

add_filter( 'woocommerce_products_admin_list_table_filters', 'my_woocommerce_products_admin_list_table_filters' );

function my_woocommerce_products_admin_list_table_filters( $filters ) {
    // to remove the category filter
    if( isset( $filters['product_category'] ) ) {
        unset( $filters['product_category'] );
    }

    // to remove the product type filter
    if( isset( $filters['product_type'] ) ) {
        unset( $filters['product_type'] );
    }

    // to remove the stock filter
    if( isset( $filters['stock_status'] ) ) {
        unset( $filters['stock_status'] );
    }

    return $filters;
}

您可以尝试使用挂钩在 admin_head 操作挂钩中的自定义函数来隐藏下拉选择器字段。您需要将 CSS ID #my_selector_id 替换为您要隐藏的选择器的 ID 或 class(使用浏览器代码检查器找到正确的选择器),您可以查看如果 属性 通过转到浏览器的开发人员工具并选择每个元素按预期工作。