WooCommerce: View Thank You Page @ Order Admin

I’ve been testing for over an hour but finally I found a way to make this work. When you are in “Edit Order” view under WordPress Dashboard > WooCommerce > Orders, there is a dropdown of “Order actions”: “Email invoice”, “Resend new order notification”, etc.

A major problem I’ve always had while troubleshooting or working on the WooCommerce thank you page was that I had to build that URL by hand in order to view it again or to avoid placing yet another test order (it follows the format e.g. https://example.com/checkout/order-received/214008/?key=wc_order_aHB6YrmLOZIKP).

Well, from today, you can access that order thank you page URL directly from the “Order actions” dropdown. Enjoy!

Here’s our brand new order action: “Display thank you page”. Simply select and then click on the right arrow, and you will be automatically redirected to the order’s thank you page!

PHP Snippet: Add “View Thank You Page” to “Order actions” @ Edit Order WP Admin Pages

Note: remove the $order->has_status() check if you wish this to appear for ALL order statuses.

/**
 * @snippet       View Thank You Page @ Edit Order Admin
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'woocommerce_order_actions', 'bbloomer_show_thank_you_page_order_admin_actions', 9999, 2 );
 
function bbloomer_show_thank_you_page_order_admin_actions( $actions, $order ) {
   if ( $order->has_status( wc_get_is_paid_statuses() ) ) {
      $actions['view_thankyou'] = 'Display thank you page';
   }
   return $actions;
}
 
add_action( 'woocommerce_order_action_view_thankyou', 'bbloomer_redirect_thank_you_page_order_admin_actions' );
 
function bbloomer_redirect_thank_you_page_order_admin_actions( $order ) {
	$url = add_query_arg( 'adm', $order->get_customer_id(), $order->get_checkout_order_received_url() );
	add_filter( 'redirect_post_location', function() use ( $url ) {
		return $url;
	});
}

add_filter( 'determine_current_user', 'bbloomer_admin_becomes_user_if_viewing_thank_you_page' );

function bbloomer_admin_becomes_user_if_viewing_thank_you_page( $user_id ) {
	if ( ! empty( $_GET['adm'] ) ) {
		$user_id = wc_clean( wp_unslash( $_GET['adm'] ) );
	}
   return $user_id;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Redirect to Custom Thank you Page
    How can you redirect customers to a beautifully looking, custom, thank you page? Thankfully you can add some PHP code to your functions.php or install a simple plugin and define a redirect to a custom WordPress page (as opposed to the default order-received endpoint). This is a great way for you to add specific up-sells, […]
  • WooCommerce: How to Add a Custom Checkout Field
    Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
  • WooCommerce: Get Order Data (total, items, etc) From $order Object
    As a WooCommerce development freelancer, every day I repeat many coding operations that make me waste time. One of them is: “How to get ____ if I have the $order variable/object?“. For example, “How can I get the order total“? Or “How can I get the order items“? Or maybe the order dates, customer ID, […]
  • WooCommerce: Add Content to the Thank You Page
    A client of mine wanted to add some text to the thank you page, the page that customers see after they place an order via the default WooCommerce Checkout page. In this case scenario, they wanted to add a special coupon discount in order to entice buyers to go back to the website and buy […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

36 thoughts on “WooCommerce: View Thank You Page @ Order Admin

  1. Hello,

    I added the snipet, the Display thank you page display on the select, but when I click on the arrow, I’m not redirected to the thank you page, the admin page of the order is just reloaded.

    1. Even if you temporarily disable all plugins except Woo?

  2. Hello. The code is not working. I get this error:
    : Uncaught Error: Call to a member function get_billing_first_name() on bool

    Woocommerce: Version 8.3.1
    PHP: 7.4

    Thank you

    1. Hello Vassos, not sure my snippet uses the “get_billing_first_name” function?

  3. Hi,

    Didn’t want to edit my functions.php file because i’m not using a child theme. So tested with a php snippet plugin and it does work. Using Code Snippets by Code Snippets Pro. Tried WPcode and didn’t work for me.

  4. Hi,

    Just discovered this snippet, but it does not seem to be working on WooCommerce 8.1.1.
    Would an update to work with v8.x be possible?

    Thanks.

    1. Hello Michael, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  5. Hey Rodolfo,

    It seems like this snippet doesn’t work anymore for me on WC 7.8.2.
    It’s pretty useful and it used to work perfectly tho, but I now got this message= “Please log in to your account to view this order. ”

    Can anyone please kindly confirm ?
    Thanks !

    1. Good point. This now happens for non-guest orders since Woo 7.8 I believe – now it’s required the user is logged in before viewing their thank you page… so the admin can’t see the Thank You page of non guest-orders!

      I’ve added a fix to the snippet now, see if it works?

      1. Hi Rodolfo,
        Yes, this was working for me, pre-7.8, but I’m still getting the ‘log in’ message. I’m using your fixed snippet. It seems these pages are now off limits to admins.

        Thanks.

        1. The latest snippet version works for me. Try clearing caches and see if the problem is there

          1. Ace ! You fixed it, thanks a million ๐Ÿ™‚

  6. Awesome! Thanks so much, works on WC 7.7.2

  7. I just tried this out on my site and it works in April 2023. Thanks!

  8. I tried this code but its not working.
    know why?
    i got these error:
    syntax error, unexpected ‘function’ (T_FUNCTION)

    1. The syntax error should also tell you the position (line) and file where the error is. Can you share that please?

  9. Beautiful. Shopify has this built in and I was doing it manually in woo. Keep up the good work.

  10. hi there
    FYI This was working but now isn’t. It just isn’t there, in the box in the admin page at all.
    We have a seasonal product and so I don’t know how long this hasn’t been working (few months max)
    Woodmark Theme
    Every other snippet I have is working as far as I am aware.
    Thank you for all the work you do.
    Amy

    1. Still works for me. Is the order status within the “wc_get_is_paid_statuses” array?

  11. The code works perfect, except for one thing. Currently the thank you page opens in the same window and so it makes me exit the backend. Is there a way to open it in a new tab?

    1. Hello Nerea, thanks so much for your comment! Yes, may be possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  12. Thank you very much! excellent.
    Can you help me put a link similar to this one on the My Account page? With that the customer has access when they need it.

    1. Hi Ricardo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  13. Never thought about this functionality, but now I need to test and see it working ๐Ÿ™‚

    Thanks for the codes but thank you even more for the different approaches and way of thinking that you bring here

  14. Hey Rodolfo !
    This one is brilliant, thanks !
    Although I already see a few case in which such a function can be useful, would you mind telling us more about why you implemented it so far ?

    1. Cool! For example I use it while troubleshooting Thank you page errors, or checking if Thank you page customization is working

  15. Hi Rodolfo,

    Thank you for thinking of sharing this snippet. It works great but what happens if you use a custom Thank You Page that includes extra content before the order details? How can we display that content here?

    Lyse

    1. This only works with the default WooCommerce thank you page, sorry. Though, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  16. Very, very needed ๐Ÿ™‚ Magic! Thank You!

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *