WooCommerce is an impressive device for construction on-line retail outlets with WordPress, dealing with the entirety from product showcases to buy processing, tax control, and past.

One standout function of WooCommerce is its talent to take care of detailed order data. It meticulously retail outlets each and every facet of an order, together with the volume, foreign money, transport particulars, taxes, and extra.

This detailed data is efficacious for each retailer homeowners and shoppers. Consider making a web page the place customers can without problems take a look at their order particulars and customise it to show more information.

This information walks you during the steps to construct a customized WooCommerce web page that presentations order particulars in keeping with the order ID.

Why would you create a customized order particulars web page?

Making a customized order particulars web page in WooCommerce can be offering a number of benefits, catering to each the shop proprietor’s and the buyer’s wishes. Listed below are a couple of compelling the explanation why you could need to cross this path:

  1. Enhanced person enjoy — A customized order particulars web page means that you can provide order data that most closely fits your shoppers’ wishes. It means that you can tailor the format and content material of your web page so you’ll spotlight essential particulars equivalent to transport standing, product specifics, and supply dates, making it more straightforward for patrons to search out what they’re in search of briefly.
  2. Further options — A customized order particulars web page can provide help to so as to add unavailable options through default in WooCommerce. As an example, you’ll show customized fields like present messages, particular directions, or personalised notes distinctive to each and every order.
  3. Interactivity — A customized order particulars web page permits you to come with interactive components equivalent to growth bars for order monitoring, hyperlinks to similar merchandise, or direct get entry to to buyer toughen, offering a richer, extra attractive enjoy in your customers.
  4. Flexibility and suppleness — Making a customized order particulars web page can mean you can enforce business-specific common sense and adapt to converting wishes. You’ll show other data in keeping with standards distinctive on your retailer, equivalent to the buyer’s location or the kind of merchandise ordered.

The best way to get order information from the $order object

In WooCommerce, the $order object is a central piece that comprises the entire details about a selected order. By means of leveraging this object, you’ll retrieve more than a few information about an order, such because the order ID, order date, billing and transport data, and the goods bought.

Let’s undergo learn how to get entry to and use those other items of information from the $order object intimately.

1. Retrieve the order object

First, you should get the order object the use of the wc_get_order serve as. This serve as takes an order ID and returns the corresponding order object.

$order_id = 123; // Instance order ID
$order = wc_get_order( $order_id );

2. Elementary order data

After you have the $order object, you’ll retrieve elementary details about the order. Listed below are some examples:

  • Order ID — The original identifier for the order.
    $order_id = $order->get_id();
    echo 'Order ID: ' . $order_id;
  • Order date — The date when the order was once created.
    $order_date = $order->get_date_created();
    echo 'Order date: ' . wc_format_datetime( $order_date );
  • Order general — The overall quantity for the order.
    $order_total = $order->get_formatted_order_total();
    echo 'Order general: ' . $order_total;

3. Billing data

Billing data comprises particulars equipped through the buyer right through the checkout procedure. You’ll retrieve those particulars the use of the next strategies:

  • Billing deal with:
    $billing_address = $order->get_formatted_billing_address();
    echo 'Billing deal with: ' . $billing_address;
  • Billing e-mail:
    $billing_email = $order->get_billing_email();
    echo 'Billing e-mail: ' . $billing_email;
  • Billing telephone:
    $billing_phone = $order->get_billing_phone();
    echo 'Billing telephone: ' . $billing_phone;

4. Delivery Data

Delivery data comprises the main points of the place the order can be shipped. Very similar to billing data, you’ll get entry to those particulars the use of the $order object:

  • Delivery deal with:
    $shipping_address = $order->get_formatted_shipping_address();
    echo 'Delivery deal with: ' . $shipping_address;

5. Order pieces

You’ll retrieve the pieces integrated in an order, which is especially helpful if you wish to show bought merchandise. Right here’s learn how to get the order pieces:

$pieces = $order->get_items();
foreach ( $pieces as $item_id => $merchandise ) {
    $product_name = $item->get_name();
    $product_quantity = $item->get_quantity();
    $product_total = $item->get_total();
    echo 'Product title: ' . $product_name . '
'; echo 'Amount: ' . $product_quantity . '
'; echo 'Overall: ' . wc_price( $product_total ) . '
'; }

6. Fee and transport strategies

You’ll additionally retrieve details about the fee and transport strategies used for the order:

  • Fee manner:
    $payment_method = $order->get_payment_method_title();
    echo 'Fee manner: ' . $payment_method;
  • Delivery manner:
    $shipping_methods = $order->get_shipping_methods();
    foreach ( $shipping_methods as $shipping_method ) {
    echo 'Delivery manner: ' . $shipping_method->get_name();
    }

7. Order standing

The standing of the order will also be useful for more than a few functionalities, equivalent to monitoring the growth of the order:

$order_status = wc_get_order_status_name( $order->get_status() );
echo 'Order standing: ' . $order_status;

Making a web page to show order particulars through order ID

To offer a continuing enjoy in your shoppers, making a customized web page the place they are able to view their order particulars through merely coming into their order ID is recommended.

Let’s information you thru making a web page, together with putting in place the template and exhibiting the order data.

Step 1: Create a customized web page template

First, create a customized web page template to your WordPress theme. This template can be used to show the order particulars.

To try this, navigate on your undertaking’s supply code. In the event you created your undertaking with DevKinsta, that is simple to get entry to. You’ll additionally use an FTP Consumer through the use of the settings to your web site information web page (WordPress Websites > sitename > Data).

On your kid theme listing, create a brand new record named page-order-details.php. Upload the next code to this record:



No order ID equipped.

'; } ?>
Invalid order ID.

'; go back; } echo '

Order Main points

'; echo '
    '; echo '
  • Order ID: ' . $order->get_id() . '
  • '; echo '
  • Order Date: ' . wc_format_datetime( $order->get_date_created() ) . '
  • '; echo '
  • Order Overall: ' . $order->get_formatted_order_total() . '
  • '; echo '
  • Billing Cope with: ' . $order->get_formatted_billing_address() . '
  • '; echo '
  • Delivery Cope with: ' . $order->get_formatted_shipping_address() . '
  • '; echo '
  • Billing Electronic mail: ' . $order->get_billing_email() . '
  • '; echo '
  • Billing Telephone: ' . $order->get_billing_phone() . '
  • '; echo '
  • Fee Approach: ' . $order->get_payment_method_title() . '
  • '; echo '
  • Order Standing: ' . wc_get_order_status_name( $order->get_status() ) . '
  • '; echo '
'; echo '

Order Pieces

'; echo '
    '; $pieces = $order->get_items(); foreach ( $pieces as $item_id => $merchandise ) { echo '
  • '; echo 'Product Identify: ' . $item->get_name() . '
    '; echo 'Amount: ' . $item->get_quantity() . '
    '; echo 'Overall: ' . wc_price( $item->get_total() ) . '
    '; echo '
  • '; } echo '
'; }

Let’s damage down this code so you recognize.

First, you realize the get_header() and get_footer() purposes, which come with the usual WordPress header and footer for the web page, making sure it maintains the web site’s general design and format.

We even have some elementary HTML markups which can be essential for exhibiting textual content on the internet. The following essential code you realize is the situation that assessments if an order_id is handed as a URL parameter.

if ( isset( $_GET['order_id'] ) ) {
    $order_id = intval( $_GET['order_id'] );
    display_order_details( $order_id );
} else {
    echo '

No order ID equipped.

'; }

What it does is if an order_id exists, it sanitizes the enter the use of intval() and calls the display_order_details serve as. If no order_id is equipped, it outputs a message indicating this.

The display_order_details serve as is the serve as declared beneath get_footer(). This serve as takes the order ID as an enter and retrieves the corresponding order object the use of wc_get_order().

If the order ID is invalid, it outputs an error message. Differently, it retrieves and presentations more than a few order particulars equivalent to order ID, date, general, billing and transport addresses, e-mail, telephone, fee manner, and order standing in an unordered listing.

Moreover, it loops during the order pieces and presentations the product title, amount, and general value for each and every merchandise in any other unordered listing.

Step 2: Upload the template on your theme and Create a brand new web page in WordPress

Save the page-order-details.php record to your kid theme listing. This will likely make the template to be had for variety when growing a brand new web page in WordPress.

Subsequent, cross to Pages > Upload New to your WordPress admin dashboard. Give the web page a reputation, after which within the Web page Attributes segment at the proper, make a choice the Order Main points template from the Template dropdown.

In the event you don’t see the Web page Attributes segment, you’ll navigate again to Pages, the place you’ll see a listing of all pages with some choices whilst you hover over each and every web page. Choose Fast Edit, after which you’ll see the Web page Attributes segment.

Put up the web page, and you’ll now take a look at the customized order particulars web page.

To check, navigate on your browser and append ?order_id=ORDER_ID to the URL, changing ORDER_ID with a legitimate WooCommerce order ID. For instance, https://yourwebsite.com/order-details/?order_id=70

This must show the order particulars for the desired order ID.

Order details from the order ID
Order particulars from the order ID.

You’ll then upload styling to the template as you prefer.

Developing an order particulars web page the use of WooCommerce order monitoring shortcode

An alternative choice you will not be conscious about is the WooCommerce order monitoring shortcode, which gives a UI for customers to seek for their order particulars through coming into their order quantity and e-mail deal with.

Order details from WooCommerce order tracking shortcode
Order particulars from WooCommerce order monitoring shortcode.

This web page presentations the order quantity, date, standing, pieces, transport, and billing deal with. This will also be helpful if you don’t intend to turn extra detailed data.

Developing an order monitoring web page the use of the WooCommerce order monitoring shortcode is a simple approach to toughen buyer enjoy with out delving into customized coding.

To try this, practice those steps:

  1. Log into your WordPress dashboard.
  2. Subsequent, create a brand new web page through navigating to Pages > Upload New.
  3. Give the web page a name, and within the web page editor, upload the next shortcode:
    [woocommerce_order_tracking]
  4. Subsequent, click on the Put up button to make the web page are living.

It’s so simple as that. However this won’t provide the flexibility you want.

Abstract

Developing an order particulars web page in WooCommerce complements the buyer enjoy through offering simple get entry to to reserve data, making improvements to transparency and buyer pleasure.

In case you are experiencing slowness to your WordPress retailer, particularly huge retail outlets with a variety of merchandise, it is very important to understand that a good portion of your web site’s efficiency will depend on the high quality of your web hosting.

Thankfully, with Kinsta as your web hosting supplier in your WooCommerce retailer, you gained’t wish to concern about this.

The publish Developing a web page to show WooCommerce order particulars through order ID seemed first on Kinsta®.

WP Hosting

[ continue ]