How to Get Order->Price In Woocommerce?

6 minutes read

In WooCommerce, you can retrieve the order price by using the order object. You can get the order object by using the order ID or order number. Once you have the order object, you can use the get_total method to get the total price of the order. Alternatively, you can also get the subtotal or any other specific price components of the order by using the appropriate method provided by the order object. This allows you to retrieve and display the order price in your WooCommerce store as needed.

Best WooCommerce Cloud Hosting Providers of May 2024


Rating is 5 out of 5


  • Ultra-fast Intel Core
  • High Performance and Cheap Cloud Dedicated Servers
  • 1 click install Wordpress
  • Low Price and High Quality
Digital Ocean

Rating is 5 out of 5

Digital Ocean

  • Active Digital Community
  • Simple Control Panel
  • Starting from 5$ per month

Rating is 5 out of 5



Rating is 5 out of 5


How to fetch order price via API in WooCommerce?

To fetch order price via API in WooCommerce, you can use the following steps:

  1. Obtain the order ID for the specific order you want to fetch the price for. You can do this by querying the list of orders through the WooCommerce REST API.
  2. Use the order ID to access the specific order details through the WooCommerce REST API endpoint for orders. You can make a GET request to the endpoint /wp-json/wc/v3/orders/{order_id}.
  3. Parse the JSON response from the API request to retrieve the order price. The price information will typically be found in the total field within the order details.
  4. Handle the fetched order price data as needed in your application.

Here's an example code snippet in Python using the requests library to fetch the order price:

import requests

url = ''
response = requests.get(url, auth=('consumer_key', 'consumer_secret'))

if response.status_code == 200:
    order_data = response.json()
    order_price = order_data['total']
    print(f"The price of the order is {order_price}")
    print(f"Failed to fetch order price. Status code: {response.status_code}")

Replace, consumer_key, consumer_secret, and 1234 with your actual WooCommerce site URL, consumer key, consumer secret, and the specific order ID you want to fetch the price for.

Remember to properly handle errors and exceptions in your code to ensure robustness and reliability in fetching the order price via the WooCommerce API.

How to get the order price in WooCommerce?

To get the order price in WooCommerce, you can use the following PHP code snippets:

  1. Get the order total price for a specific order ID:
$order = wc_get_order( $order_id );
$order_total = $order->get_total();

  1. Get the order total price for the current order (in cart):
$order_total = WC()->cart->total;

  1. Get the order subtotal price for the current order:
$order_subtotal = WC()->cart->subtotal;

You can use these code snippets in your theme's functions.php file or in a custom plugin to retrieve the order price in WooCommerce. Just make sure to replace $order_id with the actual order ID if you are using the first code snippet for a specific order.

How to display the order shipping price in WooCommerce?

To display the order shipping price in WooCommerce, you can follow these steps:

  1. Go to the WordPress admin dashboard and navigate to WooCommerce > Settings.
  2. Click on the Shipping tab.
  3. Under the Shipping Options section, make sure that the "Enable shipping" checkbox is checked.
  4. Scroll down to the Shipping Classes section and click on the + icon to add a new shipping class.
  5. Enter a name for the shipping class (e.g., Standard Shipping) and set the shipping rate for this class.
  6. Save your changes.
  7. Go to the Products tab in the WooCommerce settings.
  8. Edit the product for which you want to display the shipping price.
  9. Scroll down to the Product Data section and click on the Shipping tab.
  10. Select the shipping class you created earlier from the dropdown menu.
  11. Update the product.
  12. Now when a customer adds the product to their cart and proceeds to checkout, they will see the shipping price displayed based on the shipping class you assigned to the product.

How to calculate order price in WooCommerce?

To calculate the order price in WooCommerce, you need to consider the following factors:

  1. Product Prices: Add up the prices of all the products in the order.
  2. Shipping Costs: If there are any shipping costs associated with the order, add them to the total price.
  3. Taxes: Calculate any applicable taxes based on the customer's location and add them to the total price.
  4. Discounts: Subtract any discounts or coupons that are applied to the order.
  5. Fees: If there are any additional fees such as handling fees, add them to the total price.

Once you have calculated all of these factors, add them together to get the final order price. You can also use WooCommerce plugins or tools to automate this calculation process and display the order price to the customer before they checkout.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

To get the order date in WooCommerce, you can use the following code snippet:$order = wc_get_order( $order_id ); $order_date = $order->get_date_created();This code retrieves the order object using the order ID and then gets the created date of the order. Yo...
To get the purchase date from a WooCommerce order, you can retrieve the order's meta data using the order ID. The purchase date is stored in the order's meta data under the key '_completed_date'. You can use the get_post_meta() function to retr...
To add a new order status in WooCommerce, you need to follow the steps below:Access the WordPress dashboard of your WooCommerce store by logging in to your admin account. Navigate to the "WooCommerce" menu option on the left-hand side of the dashboard....