在 Woocommerce 中删除管理员添加订单上的国家/地区账单和送货字段

Remove country billing and shipping fields on admin add order in Woocommerce

在管理员中,当您点击添加订单时,我不知道如何删除账单和送货国家字段。我不想使用 CSS 来隐藏字段,因为在前端查看订单时我需要隐藏国家/地区 (form-pay.php).

我尝试了以下从结帐中删除这些字段的正常方法,但它在这里没有效果。

function custom_checkout_fields( $fields ) {
    unset($fields['billing']['billing_country']);
    return $fields;
}

add_filter('woocommerce_checkout_fields' , 'custom_checkout_fields');

要删除管理员添加新订单页面上的送货和账单国家字段,您将使用以下内容:

// Admin billing fields
add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1 );
function custom_admin_billing_fields( $billing_fields ) {
    global $pagenow;
    if( $pagenow === 'post-new.php' && isset($_GET['post_type']) && $_GET['post_type'] === 'shop_order' ){
        unset($billing_fields['country']); // remove billing country field
    }
    return $billing_fields;
}

// Admin shipping fields
add_filter( 'woocommerce_admin_shipping_fields', 'custom_admin_shipping_fields', 10, 1 );
function custom_admin_shipping_fields( $shipping_fields ) {
    global $pagenow;
    if( $pagenow === 'post-new.php' && isset($_GET['post_type']) && $_GET['post_type'] === 'shop_order' ){
        unset($shipping_fields['country']); // remove shipping country field
    }
    return $shipping_fields;
}

此代码位于您的活动子主题(或主题)的 function.php 文件中。已测试并有效。