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        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @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

  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]
  • WooCommerce: Redirect to Custom Thank you Page
    How can you redirect customers to a beautifully looking, custom, thank you page? Thankfully you can add some PHP code to your functions.php or install a simple plugin and define a redirect to a custom WordPress page (as opposed to the default order-received endpoint). This is a great way for you to add specific up-sells, […]
  • WooCommerce: Disable Payment Gateway by Country
    You might want to disable PayPal for non-local customers or enable a specific gateway for only one country… Either way, this is a very common requirement for all of those who trade internationally. Here’s a simple snippet you can further customize to achieve your objective. Simply pick the payment gateway “slug” you want to disable/enable […]

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

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

  1. 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

  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 ) );
        }
    }
    
  3. 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!

  4. 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 *