SEOS THEMES

Free WordPress Themes
logo My Account
Buy All 33 Premium Themes For the Price Of €69.94

WooCommerce How To Get Order ID

How To Get Order ID


// Get Order ID
$order->get_id();

WC_Data::get_id() – Returns the unique ID for this object. Parameters returns intiger.

$int = WC_Data::get_id();

wc_get_order( $order_id ) is the WooCommerce function which is required to fetch the order object. This function returns false when it is called before the post type is registered. How to get the order object. The code below will help you.
$order = new WC_Order( $order_id );

How To Get Order Key


// Get Order Key
$order->get_order_key();

$string = WC_Order::get_order_key( $context );

Added a check to make sure it’s a real order.

$order = wc_get_order($order_id);
if ($order && !is_wp_error($order)) {
$order_key = $order->get_order_key();
}

^