How to get order->price in woocommerce?

by haylee.mertz , in category: PHP CMS , 7 months ago

How to get order->price in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , 7 months ago

@haylee.mertz 

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

1
2
$order = wc_get_order( $order_id );
$order_total = $order->get_total();


In this code snippet:

  • $order_id is the ID of the order whose price you want to retrieve.
  • wc_get_order() retrieves the order object based on the order ID.
  • $order->get_total() gets the total price of the order.


You can use this code snippet in your theme's functions.php file or in a custom plugin to retrieve the order price in WooCommerce.