从 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;
}