Need momentum? We're now taking on new clients... Web, Marketing, SEO, AI/LLM... Please reach out.

RARE FIND: Display a Woocommerce Order in a Nice Clean HTML Formatted Output

RARE FIND: Display a Woocommerce Order in a Nice Clean HTML Formatted Output

I’ve been looking around for this for way too long, and finally just had to quickly write my own.

This is based on the HTML & CSS Styles and Classes from the Storefront Theme, however this will certainly still work and display in any theme you add it to… You may just need to add some styles to control the look of it all.

I am always available to help you with this & any other dev work you need if you reach out on the Contact Page.

A few helpful links are also included as comments within the code for additional order meta fields from both Business Bloomer and Stack Overflow if needed. Huge shoutout to both of them for all of the help over the years.

Thanks for visiting & good luck with this code! Should work as it, just insert your order ID or even add it as a URL parameter as you can see how I’ve been doing it.

By the way, for anyone that is new to WordPress Development, this is PHP code that should live inside your WordPress theme or plugin PHP files.

            $order_id = $_GET['order_id'];

            $order = new WC_Order($order_id); // Order id
            $order_id = $order->get_id();
            $order_number = get_post_meta($order_id,"express_checkout_order_number",true);
            if ($order_number=="") $order_number = $order_id;
            $order_status = $order->get_status();
            $order_date = $order->get_date_created();
            $order_billing_address = $order->get_formatted_billing_address();
            $order_shipping_address = $order->get_formatted_shipping_address();
            if ($order_shipping_address=="") $order_shipping_address = $order_billing_address;
            
            $get_formatted_order_total = $order->get_formatted_order_total();
            $get_subtotal = $order->get_subtotal();
            $get_total = $order->get_total();

            //more order fields can be found here
            //https://www.businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/
            
            echo '

Order #'.$order_number.' was placed on '.date_format($order_date,"D M d, Y g:ha").' and is currently '.$order_status.'.

'; echo '

Order details

'; // Get and Loop Over Order Items foreach ( $order->get_items() as $item_id => $item ) { $product_id = $item->get_product_id(); $variation_id = $item->get_variation_id(); $product = $item->get_product(); $product_name = $item->get_name(); $quantity = $item->get_quantity(); $subtotal = $item->get_subtotal(); $total = $item->get_total(); $tax = $item->get_subtotal_tax(); $taxclass = $item->get_tax_class(); $taxstat = $item->get_tax_status(); $allmeta = $item->get_meta_data(); $somemeta = $item->get_meta( '_whatever', true ); $product_type = $item->get_type(); echo ' '; } echo '
Product Total
'.$product_name.' × '.$quantity.' $'.number_format($total,2).'
Subtotal: $'.number_format($get_subtotal,2).'
Total: $'.number_format($get_total,2).'

Billing address

'.$order_billing_address.'

Shipping address

'.$order_shipping_address.'
'; //need more order data? output all order data via get_order_details function here //https://stackoverflow.com/questions/39401393/how-to-get-woocommerce-order-details

Categories: Code, PHP, Woocommerce, Wordpress

Simple Web Help Live Chat

We’ve made it even easier to reach us—our live chat has moved to a text-based system so you can connect with us instantly from anywhere, not just from your browser.

Text “WEB” to 952-248-8883 to start a new conversation and get help right from your phone.

Looking forward to connecting!