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();
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();
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.
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...