How to get the order id from the order key in woocommerce?

by filiberto , in category: PHP CMS , a month ago

How to get the order id from the order key in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , a month ago

@filiberto 

To get the order ID from the order key in WooCommerce, you can use the following code snippet:

1
2
3
4
5
6
// Get order ID from order key
$order_key = 'YOUR_ORDER_KEY';
$order_id = wc_get_order_id_by_order_key( $order_key );

// Output order ID
echo 'Order ID: ' . $order_id;


Replace 'YOUR_ORDER_KEY' with the actual order key you want to retrieve the order ID for. This code snippet uses the wc_get_order_id_by_order_key function provided by WooCommerce to fetch the order ID associated with the given order key.