I will customize the thankyou page from my WoocCommerce shop. For this I added a blanc thankyou.php into the WooCommerce checkout directory.
I tried this code
function get_order($order_id) {
echo $order_id;
}
add_action('woocommerce_thankyou', 'get_order');
But the variable $order_id is empty.
Is there somebody who knows how I get the order id on the thankyou page?
If Url is like www.example.com/checkout/order-received/1234/?key=wc_order_s5ou6md6nTZDds you can use the following to get the order id:
global $wp;
if ( isset($wp->query_vars['order-received']) ) {
$order_id = absint($wp->query_vars['order-received']); // The order ID
$order = wc_get_order( $order_id ); // The WC_Order object
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With