Skip to content

Instantly share code, notes, and snippets.

@AnupRaj
Last active August 1, 2018 07:05
Show Gist options
  • Save AnupRaj/1c171ba0664deac6495e0072baba3bd5 to your computer and use it in GitHub Desktop.
Save AnupRaj/1c171ba0664deac6495e0072baba3bd5 to your computer and use it in GitHub Desktop.
WooCommerce order-received page shows 404 error
// WooCommerce Order Received Page 404 fix
// the correct url of order-received page is https://example.com/checkout/order-received/ which should work
// if you will try to use different url like https://example.com/order-received/ then you will get 404
// You can have custom url / page / slug and use shortcode [my_order_id] [my_order_key] in the page
// add following function in your theme's functions.php file
function get_order_id_thankyou( $atts ) {
// Only in thankyou "Order-received" page
if( ! is_wc_endpoint_url( 'order-received' ) )
return; // Exit
global $wp;
// Get the order ID
$order_id = absint( $wp->query_vars['order-received'] );
if ( empty($order_id) || $order_id == 0 )
return; // Exit;
// Testing output (always use return with a shortcode)
return '<p>Order ID: ' . $order_id . '</p>';
}
add_shortcode( 'my_order_id', 'get_order_id_thankyou');
function get_order_key_thankyou( $atts ) {
// Only in thankyou "Order-received" page
if( ! is_wc_endpoint_url( 'order-received' ) )
return; // Exit
global $wp;
// Get the order ID
$order_id = absint( $wp->query_vars['order-received'] );
if ( empty($order_id) || $order_id == 0 )
return; // Exit;
// Testing output (always use return with a shortcode)
return '<p>Order Key: ' . get_post_meta( $order_id, '_order_key', true ) . '</p>';
}
add_shortcode( 'my_order_key', 'get_order_key_thankyou');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment