Get the order id on WooCommerce “Order received” Thankyou page

Rate this post

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 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

Leave a Reply

Your email address will not be published.

Back to top button