簡體   English   中英

在 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 文件中。 測試和工作。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM