Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the order id on WooCommerce "Order received" Thankyou page

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?

like image 326
Stefan Avatar asked Oct 22 '25 13:10

Stefan


1 Answers

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
}
like image 83
LoicTheAztec Avatar answered Oct 25 '25 03:10

LoicTheAztec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!