How can I get the order ID from the order Key in WooCommerce?
endpoint, orders, php, woocommerce, wordpress
Solution
On Order Received, Order Pay and View Order pages, you can get the order id from URL like:
1). On Order Received (Thankyou) page:
$order_id = absint( get_query_var('order-received') );
2). On Order Pay page:
$order_id = absint( get_query_var('order-pay') );
3). On View Order pages:
$order_id = absint( get_query_var('view-order') );
Now you can use `wc_get_order_id_by_order_key()` WooCommerce function like:
$order_id = wc_get_order_id_by_order_key( $order_key );
Problem
How do I retrieve the order ID from the order KEY in WooCommerce? (PHP code) e.g. I have the order KEY which looks like 'wc_order_qkTc2RVyGtVil' and I want to get the order ID which looks like '1950'. background: I only get an link which contains the order KEY. Thats why I cant use the order OBJECT to get the ID.