How can I get the order ID in WooCommerce? olatechproMarch 26, 202313 Views How do I retrieve the order ID in WooCommerce? Post Views: 13 Related postsGet rid of this Strict Standards warningWooCommerce: get_current_screen not working with multi languageCan’t login on WordPressForce HTTPS using .htaccess – stuck in redirect loopWordPress: Ajax not working to insert, query and result dataHow Can I pass an image file to wp_handle_upload?
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; Log in to Reply
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())); Log in to Reply
I didnt test it and dont know were you need it, but: $order = new WC_Order(post->ID); echo $order->get_order_number(); Let me know if it works. I belive order number echoes with the “#” but you can split that if only need only the number. Log in to Reply
As of woocommerce 3.0 $order->id; will not work, it will generate notice, use getter function: $order->get_id(); The same applies for other woocommerce objects like procut. Log in to Reply
$order = new WC_Order( $post_id ); If you echo $order->id; then you’ll be returned the id of the post from which the order is made. As you’ve already got that, it’s probably not what you want. echo $order->get_order_number(); will return the id of the order (with a # in front of it). To get rid of the #, echo trim( str_replace( '#', '', $order->get_order_number() ) ); as per the accepted answer. Log in to Reply
As LoicTheAztec mentioned here: https://stackoverflow.com/a/67182262/4638682 You get get this in several ways, within several template. Like so: $order_id = absint( get_query_var('view-order') ); Log in to Reply
Current method:
The current way of accomplishing this is by using this function:
That should return the order id without “#”.
Old method:
In older versions of WooCommerce, you may need to access it as a property instead:
it worked. Just modified it
I didnt test it and dont know were you need it, but:
Let me know if it works.
I belive order number echoes with the “#” but you can split that if only need only the number.
As of woocommerce 3.0
will not work, it will generate notice, use getter function:
The same applies for other woocommerce objects like procut.
If you
then you’ll be returned the id of the post from which the order is made. As you’ve already got that, it’s probably not what you want.
will return the id of the order (with a # in front of it). To get rid of the #,
as per the accepted answer.
As LoicTheAztec mentioned here: https://stackoverflow.com/a/67182262/4638682
You get get this in several ways, within several template. Like so: