Website Building » WooCommerce » How Do I Get the Total Order in WooCommerce?

How Do I Get the Total Order in WooCommerce?

Last updated on January 19, 2023 @ 1:17 pm

Are you looking to find the total order amount in WooCommerce? This can be helpful if you’re wanting to create a custom report or if you need to process an order programmatically.

In this article, we’ll show you a few different ways that you can get the total order amount in WooCommerce.

Method 1: Get the Total Order Amount from the Order Object

If you already have an instance of the WC_Order object, then you can get the total order amount by using the get_total() method. Here’s an example:

PRO TIP: If you are using WooCommerce to manage your online store, you may be wondering how to get the total order amount in WooCommerce. This can be a tricky task, as there are a few different ways to calculate the total order amount.

The first thing you need to do is decide whether you want to include shipping and taxes in the total order amount. If you do want to include these items, you need to add them into the WooCommerce order totals section. To do this, go to WooCommerce > Settings > Order Totals. From here, you can add or remove fields as needed.

Once you have decided which fields to include, you need to calculate the total order amount. To do this, go to the Orders page and select the order you want to calculate the total for. On the right side of the screen, you will see an “Order Total” section. This is where you will enter the quantities of each item and the shipping cost. Once you have entered all of this information, click on the “Calculate Total” button.

You should now see the total order amount displayed on the screen.

$order = new WC_Order( $order_id );
$total = $order->get_total();

Method 2: Get the Total Order Amount Using the WC_Order_Factory Class

If you don’t have an instance of the WC_Order object, then you can use the WC_Order_Factory class to get an instance of the WC_Order object. Once you have an instance of the WC_Order object, you can use the get_total() method to get the total order amount. Here’s an example:

$order = wc_get_order( $order_id );
$total = $order->get_total();

Conclusion:

There are two primary ways that you can get the total order amount in WooCommerce. The first way is to get it from the Order object itself using the .get-total(). The second way is to use the .WC-Order-Factory, which will give you an instance of the Order object, and then access it using .get-total().

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.