從 WooCommerce Checkout 頁面刪除賬單明細欄位

預設的 WooCommerce 結帳表單附帶了幾個欄位,供客戶輸入其結算明細。但在某些情況下,你可能希望隱藏其中一些欄位。例如,如果你只銷售虛擬產品,則可以刪除帳單地址等欄位。

使用以下程式碼段從 WooCommerce 結帳頁面中刪除或隱藏欄位。

//Remove Billing Details Fields from WooCommerce Checkout Page
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
 
function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_country']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_phone']);
    unset($fields['order']['order_comments']);
    unset($fields['billing']['billing_email']);
    unset($fields['account']['account_username']);
    unset($fields['account']['account_password']);
    unset($fields['account']['account_password-2']);
    return $fields;
}