Fatal error: Uncaught Error: Class "WC_Order" not found Can't get my order details in WC

Viewed 28

whenever I use WC_Order() in a plugin that I created for getting the order data I get Fatal error: Uncaught Error: Class "WC_Order" not found

What I want to achieve is getting the order data like shipping address, product name, product description and client name to make another API call that associate with the Woocommerce order

this's the simple popular code

global $woocommerce, $post;
$order =  new WC_Order(1413);

$order_data = $order->get_data(); // The Order data

the error

Fatal error: Uncaught Error: Class "WC_Order" not found in C:\xampp\htdocs\wordpress\wp-content\plugins\Scalablepress\index.php
1 Answers

Try to use this:

$order = wc_get_order( $order_id );

With that, you can access all other order data like this:

$order_id  = $order->get_id();
$parent_id = $order->get_parent_id();
$user_id   = $order->get_user_id();
$user      = $order->get_user();

The question has been answered something like this before: How to get WooCommerce order details

Related