-2

I am trying to get wooCommerce order id. I wrote the following script in functions.php but i getting 0.Can you tell how to get the Id.

global $woocommerce, $post;
  $order = new WC_Order($post->ID);
  $order_id=$order->get_id();

2 Answers2

0

You can get order id by this function. get_order_number() You can use the code given below.

global $woocommerce, $post;
$order = new WC_Order($post->ID);
$order_id = $order->get_order_number();

You can check additional documentation from this link.

Let me know if it works for you.

Masud Rana
  • 304
  • 1
  • 6
0

Have you tried this ?

$order_data = wc_get_order( $order_id );
echo $order_data->get_id();

How you are calling the above code(like hook) in functions.php...

json
  • 165
  • 7