如何在WooCommerce自定义订单支付页面显示账单与配送字段
Hey there, let’s work through this issue where your customers aren’t seeing billing and shipping fields on the payment page (form-pay.php). I’ll break down the most common causes and fixes step by step:
1. Check if the template is actually rendering the fields
First, pop open your form-pay.php file and look for code that outputs billing/shipping fields. If this is a WooCommerce-based system (or similar), you’ll typically see action hooks like:
<?php do_action( 'woocommerce_checkout_billing' ); ?> <?php do_action( 'woocommerce_checkout_shipping' ); ?>
Or if it’s a custom system, there should be PHP loops or direct calls to pull and display the fields (e.g., echo $order->get_billing_first_name(); wrapped in form inputs).
If these sections are missing entirely, that’s the problem—add back the appropriate field-rendering code. You can reference the original default template from your theme or platform to get the correct syntax.
2. Verify the order has billing/shipping data attached
Head to your admin backend and pull up the customer’s order. Check if the billing and shipping details are saved there. If the data exists in the backend but doesn’t show up on the frontend:
- Make sure
form-pay.phpis correctly fetching the order object. Look for code like$order = wc_get_order( $order_id );(for WooCommerce) or your system’s equivalent. - Double-check that the template is accessing the right metadata keys. For example, using
$order->get_billing_address_1()instead of a misspelled or deprecated key.
3. Rule out CSS hiding the fields
Sometimes fields are actually present in the DOM but hidden by CSS. Right-click the empty area where fields should be, select "Inspect" (browser dev tools), and look for elements with classes like billing-fields or shipping-fields. If you see them but they have display: none; or visibility: hidden; applied:
- Track down the CSS rule causing this (check your theme’s stylesheet or inline styles)
- Modify or remove the rule to make the fields visible
4. Check if hooks/filters are removing the fields
If you’re using a plugin-based system (like WooCommerce), custom code in your theme’s functions.php or a custom plugin might be unhooking the field-rendering actions. Search for lines like:
remove_action( 'woocommerce_checkout_billing', 'woocommerce_checkout_billing_fields' );
If you find such code, comment it out or adjust it to only target specific scenarios (not all payment pages).
5. Restore a backup of the template
If you’ve recently modified form-pay.php, there’s a chance you accidentally deleted the field sections. Compare your current file to a backup (or the original template from your theme’s download) to spot missing code blocks. Restore the missing parts if needed.
Start with the first two checks—they’re the most likely culprits. Let me know if you hit a snag with any of these steps!
内容的提问来源于stack exchange,提问作者Jean R.

