WooCommerce: Display Customer Address @ Order Pay

The WooCommerce Order Pay page URL is generated by the store admin while creating a manual order from the backend. This URL is then forwarded onto the client, where they can pay for the order and complete their purchase.

The other annoying thing about the order pay page, together with strict page permissions, is the fact that the Order Pay page shows no customer billing/shipping address whatsoever. The customer needs to trust in you 100000%, because they’re about to submit a payment without knowing whether they’re paying for the right thing.

Let’s see how we can add the billing/shipping customer address at the top of the Order Pay page. Please note that printing personal data on a public URL is dangerous, so you need to make sure you don’t share the Order Pay URL with anyone but the customer in such case.

So, here’s a quick fix for you. Enjoy!

The default Order Pay page does not display the customer billing and shipping addresses. With the snippet below you can achieve exactly that (highlighted with a red squadre in the screenshot)

PHP Snippet: Show Customer Billing/Shipping Addresses @ WooCommerce Order Pay Page

/**
 * @snippet       Show Addresses @ WooCommerce Order Pay
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 6
 * @community     https://businessbloomer.com/club/
 */

add_action( 'before_woocommerce_pay', 'bbloomer_order_pay_billing_address' );

function bbloomer_order_pay_billing_address() {

   // ONLY RUN IF PENDING ORDER EXISTS
	if ( isset( $_GET['pay_for_order'], $_GET['key'] ) ) {

      // GET ORDER ID FROM URL BASENAME
		$order_id = intval( basename( strtok( $_SERVER["REQUEST_URI"], '?' ) ) );
		$order = wc_get_order( $order_id );

      // INCLUDE CUSTOMER ADDRESS TEMPLATE
		wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) );

	}
}

Where to find the Order Pay page URL

Manually create an order or set an existing order to “Pending payment” status – a “Customer payment page” link will automatically show in the backend. That’s the Order Pay page!

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

11 thoughts on “WooCommerce: Display Customer Address @ Order Pay

  1. So, this shows the addresses before the email verification/login requirement (unless they actually have an account already and are already signed in).

    I doubt you could randomly get to a given pay order link with it needing to have both a valid order number AND key, so not really worried about bots trying to scrape this data. But once the customer does navigate to the link, and if they haven’t logged in yet, it shows the addresses before the email field and just doesn’t look very secure/professional.

    Shouldn’t the addresses only show up after the email validation/login?

    1. Good point. What if you switch to the ‘before_woocommerce_pay_form’ hook?

  2. Hi there,

    Probably not the best way to do this sas someone coud iterate through order numbers and get others details?

    How about?

    add_action( 'before_woocommerce_pay', 'bbloomer_order_pay_billing_address' );
     
    function bbloomer_order_pay_billing_address() {
     
        // Check key and pay for order are not empty first 
        if ( isset( $_GET['pay_for_order'], $_GET['key'] ) ) {
     
            // Sanitize the key
            $order_key = sanitize_text_field( $_GET['key'] );
     
            // Look up the order id of the WooCommerce order by the order key
            $order_id = wc_get_order_id_by_order_key( $order_key );
     
            // Get order from the order ID
            $order = wc_get_order( $order_id );
     
            // Validate the order is a real WooCommerce order
            if ( ! $order ) {
                // If order is not valid, exit the function
                return;
            }
     
            // Display the order number
            echo '<h2>Pay for Order No. ' . esc_html( $order->get_id() ) . '</h2>';
     
            // Include customer address template
            wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) );
        }
    }
    
    1. Makes a LOT of sense, thank you

  3. Hi there,

    Probably not the best way to do this sas someone coud iterate through order numbers and get others details?

    How about?

    add_action( 'before_woocommerce_pay', 'bbloomer_order_pay_billing_address' );
    
    function bbloomer_order_pay_billing_address() {
       // Check key and pay for order are not empty first
       if ( isset( "$_GET['pay_for_order'], $_GET['key'] ) ) {
     
            // Sanitize the key
            $order_key = sanitize_text_field( $_GET['key'] );
     
            // Look up the order id of the WooCommerce order by the order key
            $order_id = wc_get_order_id_by_order_key( $order_key );
     
            // Get order from the order ID
            $order = wc_get_order( $order_id );
     
            // Validate the order is a real WooCommerce order
            if ( ! $order ) {
                // If order is not valid, exit the function
                return;
            }
     
            // Display the order number
            echo '<h2>Pay for Order No. ' . esc_html( $order->get_id() ) . '</h2>';
     
            // Include customer address template
            wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) );
        }
    }
    
  4. Another excellent snippet. Works great!!

    How would one go about also adding the shipping address?

    Also, I read in the previous comment about editing the address as custom work – how big of a job would this be?

    1. Hi Cory! This should already add both Billing & Shipping.

      Editing the addresses (therefore showing forms instead), would be roughly 3-4 hours of dev work.

      1. Thanks Rodolfo,

        I am only getting the billing address: tinyurl.com/4ujdn9fc –> ignore the local pickup under address as I just put this as the street address.

        Regarding custom work – can you email me a quote for the job.

        1. Not sure to be honest, works for me out of the box: https://www.screencast.com/t/ajcKyr9MtT

          Sure the order contains physical products? Otherwise may not show shipping.

          I will email you the quote, no worries. Thank you!

  5. hi
    thanks for your solotion , but i need edit address by customer before pay in pay address link
    this code just display address
    if has adresss editable after login is good

    1. Hi Mr, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *