Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the order ID in WooCommerce?

How do I retrieve the order ID in WooCommerce?

like image 395
moslem Avatar asked Sep 02 '25 14:09

moslem


2 Answers

Current method:

The current way of accomplishing this is by using this function:

$order->get_id();

That should return the order id without "#".

Old method:

In older versions of WooCommerce, you may need to access it as a property instead:

echo $order->id;
like image 95
Elvis Fernandes Avatar answered Sep 05 '25 17:09

Elvis Fernandes


it worked. Just modified it

global $woocommerce, $post;

$order = new WC_Order($post->ID);

//to escape # from order id 

$order_id = trim(str_replace('#', '', $order->get_order_number()));
like image 33
Dip Avatar answered Sep 05 '25 16:09

Dip