You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce 3中自定义我的账户地址字段:移除与重排诉求

Customizing WooCommerce's form-edit-addresses.php: Remove Address 2 & Reorder Fields

Hey there! I’ve got you covered with this customization. The key here is to use a child theme so your changes don’t get erased when WooCommerce or your parent theme updates. Let’s walk through this step by step:

Step 1: Copy the Template to Your Child Theme

First, head to your WooCommerce plugin files: wp-content/plugins/woocommerce/templates/myaccount/
Copy the form-edit-addresses.php file and paste it into your child theme’s directory at: wp-content/themes/your-child-theme/woocommerce/myaccount/
This tells WooCommerce to prioritize your modified template over the core default.

Step 2: Remove the billing_address_2 Field

Open the copied form-edit-addresses.php in a code editor. Look for the line that renders the billing address 2 field—it’ll look like this:

woocommerce_form_field( 'billing_address_2', $address_fields['billing_address_2'] );

Delete this line entirely (or comment it out with // at the start if you want to keep a backup). If you also need to remove the shipping address 2 field, repeat this for the shipping_address_2 field further down the file.

Step 3: Reorder the Form Fields

Now rearrange the remaining fields to match your desired sequence: first_name - last_name → email - phone → company → address_1 → postcode → city → state.

Find the section for billing address fields (look for comments like <?php do_action( 'woocommerce_before_edit_address_form_billing' ); ?>). Adjust the field order to look like this:

// First Name + Last Name
woocommerce_form_field( 'billing_first_name', $address_fields['billing_first_name'] );
woocommerce_form_field( 'billing_last_name', $address_fields['billing_last_name'] );

// Email + Phone
woocommerce_form_field( 'billing_email', $address_fields['billing_email'] );
woocommerce_form_field( 'billing_phone', $address_fields['billing_phone'] );

// Company
woocommerce_form_field( 'billing_company', $address_fields['billing_company'] );

// Address Line 1
woocommerce_form_field( 'billing_address_1', $address_fields['billing_address_1'] );

// Postcode
woocommerce_form_field( 'billing_postcode', $address_fields['billing_postcode'] );

// City
woocommerce_form_field( 'billing_city', $address_fields['billing_city'] );

// State
woocommerce_form_field( 'billing_state', $address_fields['billing_state'] );

If you want the same order for shipping addresses, repeat this adjustment for the shipping field section (look for woocommerce_before_edit_address_form_shipping).

Step 4: Test Your Changes

Save the file, then navigate to your site’s My Account > Edit Addresses page. You should see:

  • No Address line 2 field for billing (and shipping if you removed it)
  • Fields arranged exactly in the order you specified

Just a quick check: Ensure mandatory fields are still present (WooCommerce handles most required field logic, but it’s good to confirm nothing breaks on submission).

内容的提问来源于stack exchange,提问作者Dom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:32:59