Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets Customer My Account Product Reviews

WooCommerce: Purchase History (With Review Buttons) @ My Account

Last Revised: Mar 2025

STAY UPDATED

If you’re running a WooCommerce store, you know how important product reviews are for building trust and boosting sales. But as your product catalog grows, it can become hard for customers to keep track of which purchases still need reviews.

That’s where a Purchase History tab comes in handy. Imagine offering your customers a simple way to see all their previous purchases, with a clear indicator of which items they haven’t reviewed yet.

In this tutorial, we’ll show you how to create a custom Purchase History tab within the My Account page. This tab will list purchased products, the date of purchase, and provide a quick “Review” link if the product hasn’t been reviewed yet.

It’s a small feature that can make a big impact on your store’s reviews and engagement. Keep reading to find the code snippet that will make it happen!

Table Of Contents
  1. PHP Snippet 1 of 2: Custom "Purchase History" Tab @ WooCommerce My Account
  2. PHP Snippet 2 of 2: "Purchase History" Tab Content

PHP Snippet 1 of 2: Custom “Purchase History” Tab @ WooCommerce My Account

First of all, let’s create a custom tab. I’m using my “Add a custom My Account tab” tutorial for this.

Note: resave / refresh your permalinks once you use the code below, otherwise the tab will give you 404 error.

/**
 * @snippet       Purchase History Tab | WooCommerce My Account
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 9
 * @community     https://businessbloomer.com/club/
 */

add_action( 'init', 'bbloomer_add_purchase_history_endpoint' );

function bbloomer_add_purchase_history_endpoint() {
    add_rewrite_endpoint( 'purchase-history', EP_ROOT | EP_PAGES );
}

add_filter( 'query_vars', 'bbloomer_purchase_history_query_vars', 0 );

function bbloomer_purchase_history_query_vars( $vars ) {
    $vars[] = 'purchase-history';
    return $vars;
}

add_filter( 'woocommerce_get_query_vars', 'bbloomer_add_wc_query_vars' );

function bbloomer_add_wc_query_vars( $vars ) {
    $vars['purchase-history'] = 'purchase-history';
    return $vars;
}

Also, let’s give it a page title:

add_filter( 'woocommerce_endpoint_purchase-history_title', 'bbloomer_purchase_history_title' );

function bbloomer_purchase_history_title( $title ) {
    return 'Purchase History';
}

Here’s the final result:

PHP Snippet 2 of 2: “Purchase History” Tab Content

Now let’s populate the tab with the list of purchased items by the current user. Each item will get a series of custom actions, and one of these may be the “Leave a Review” button in case they haven’t left a review yet!

/**
 * @snippet       Purchase History Tab Content | WooCommerce My Account
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 9
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_account_purchase-history_endpoint', 'bbloomer_display_purchase_history' );

function bbloomer_display_purchase_history() {
	
    $customer_orders = wc_get_orders( array(
        'customer_id' => get_current_user_id(),
        'status' => wc_get_is_paid_statuses(),
        'limit' => -1,
    ));
	
	 $customer = new WC_Customer( get_current_user_id() );
	 $reviewed_products = [];
    $comments = get_comments( array(
        'author_email' => $customer->get_billing_email(),
        'type' => 'review',
        'status' => 'approve',
    ));    
    foreach ( $comments as $comment ) {
        $reviewed_products[] = $comment->comment_post_ID;
    }

    if ( $customer_orders ) {
        echo '<table class="woocommerce-table shop_table shop_table_responsive">';
        echo '<thead><tr><th>Product</th><th>Date</th><th>Actions</th></tr></thead><tbody>';
        foreach ( $customer_orders as $order ) {
            foreach ( $order->get_items() as $item_id => $item ) {
                $product = $item->get_product();
                echo '<tr>';
                echo '<td><a href="' . esc_url( $product->get_permalink() ) . '">' . esc_html( $item->get_name() ) . '</a></td>';
                echo '<td>' . esc_html( wc_format_datetime( $order->get_date_created() ) ) . '</td>';
                echo '<td>';
                if ( ! in_array( $product->get_id(), $reviewed_products ) ) {
                    echo '<a class="button alt" href="' . esc_url( get_permalink( $product->get_id() ) . '#tab-reviews' ) . '">' . esc_html__( 'Add a review', 'woocommerce' ) . '</a> ';
                }
                echo '</td>';
                echo '</tr>';
            }
        }
        echo '</tbody></table>';
    } else {
        echo '<p>No purchases found.</p>';
    }

}

And this is how it will look:

In case the current user already reviewed a given product, the button won’t show. You can of course add other custom actions, such as “Share with a friend”, “Order again”, etc.

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: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back πŸ™‚ In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…
  • WooCommerce: Add First & Last Name to My Account Register Form
    Here’s yet another useful PHP snippet – and a mini-plugin alternative with super simple settings – that adds the Billing First Name and Billing Last…

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

8 thoughts on “WooCommerce: Purchase History (With Review Buttons) @ My Account”

  1. Jan
    March 25, 2025

    Hello ,
    I would like to add a thumbnail of the product to the table, but I am not really familiar with php to make this happen. I added the following line, but I can’t get the image to appear:

     echo '<a>get_permalink() ) . '"&gt;' . esc_html( $product-&gt;get_image_id() ) . '</a>';

    .

    Reply
    1. Rodolfo Melogli
      April 7, 2025

      Jan, 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!

      Reply
  2. Darren Cowley
    January 24, 2025

    This would be amazing if the leave a review buttons could be added to the existing downloads tab?!

    Reply
    1. Rodolfo Melogli
      January 25, 2025

      Sure, that’s possible as well

      Reply
      1. Darren Cowley
        February 19, 2025

        That would be amazing as in using this code there’s no tab thats added to my Account page πŸ™

        Manually going to mysite/my-account/purchase-history/ return a no purchases found in my tests πŸ™

        Reply
        1. Rodolfo Melogli
          February 24, 2025

          I believe I have this coded and working now. The tutorial will go live on March 4 at 2:09 pm Italy time: https://www.businessbloomer.com/woocommerce-add-leave-a-review-column-to-downloads-table/

          Reply
          1. Abdolaziz
            March 19, 2025

            Hello
            As for “Darren Cowley”, it doesn’t work for me and I have the same result. Maybe something is wrong with the code. I don’t have this new tab and its content.
            Note: I use WPCode pro to insert code snippets into my websites (back-end and front-end).

            Reply
            1. Rodolfo Melogli
              March 21, 2025

              Did you refresh permalinks?

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

Cancel reply

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


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: Redirect Empty Paginated Category Pages (404)
  • WooCommerce: Complete Button @ Order Admin
  • WooCommerce: Allow Guest Checkout For Existing Customers
  • WooCommerce: Simplify Free Checkout
  • WooCommerce: Inject Ad After the nth Product @ Shop Page

Latest Comments

  1. Rodolfo Melogli on WooCommerce: Prevent Duplicate Orders
  2. Rodolfo Melogli on WooCommerce: Remove “Get the app” Ad @ Admin Order Emails
  3. Rodolfo Melogli on WooCommerce: Failed Orders Monitor & Temporary Lockdown

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x