WooCommerce: Display All Products Purchased by User

When a WooCommerce customer is logged in, you might want to show them the list of previously purchased products (maybe in a custom “My Account” tab).

This is helpful when customers tend to buy the same products over and over again, and therefore you can help them “order again” without having them to search the whole product catalog again.

WooCommerce: display products bought by user via a shortcode

PHP Snippet: Display All Products Purchased by WooCommerce Customer

Once you upload the snippet to your website, you can use the following shortcode wherever you need. Please note it only works when the user is logged in, so for example the My Account page would be ideal:

[my_purchased_products]

/**
 * @snippet       Display Products Purchased by User - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */
 
add_shortcode( 'my_purchased_products', 'bbloomer_products_bought_by_curr_user' );
  
function bbloomer_products_bought_by_curr_user() {
  
    // GET CURRENT USER
    if ( 0 == get_current_user_id() ) return;
  
    // GET USER ORDERS (COMPLETED + PROCESSING)
    $customer_orders = wc_get_orders( array(
        'limit' => -1,
        'customer_id' => get_current_user_id(),
        'status' => array_keys( wc_get_is_paid_statuses() ),
        'return' => 'ids',
    ) );
  
    // LOOP THROUGH ORDERS AND GET PRODUCT IDS
    if ( ! $customer_orders ) return;
    $product_ids = array();
    foreach ( $customer_orders as $customer_order_id ) {
        $order = wc_get_order( $customer_order_id );
        $items = $order->get_items();
        foreach ( $items as $item ) {
            $product_id = $item->get_product_id();
            $product_ids[] = $product_id;
        }
    }
    $product_ids = array_unique( $product_ids );
    $product_ids_str = implode( ",", $product_ids );
  
    // PASS PRODUCT IDS TO PRODUCTS SHORTCODE
    return do_shortcode("[products ids='$product_ids_str']");
  
}

Advanced Plugin: WooCommerce Product Table

In case you don’t feel like coding, I also researched plugins for displaying products purchased by the user. I discovered that the well-known WooCommerce Product Table plugin by Barn2 has a possible workaround.Β 

This plugin lets you list any or all of your products in a searchable table layout. Most people use it to add a table view to their public-facing shop.

However, it also has a hidden feature where it lists products previously purchased by the current user. As with the above code snippet, I recommend adding this to an area for logged in users such as the WooCommerce Account page.Β 

For full setup instructions, Barn2 have provided a helpful tutorial about how to use WooCommerce Product Table to list previously purchased products.

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: Display Out of Stock Products (Shortcode)
    A client of mine wanted to show out of stock products on a separate page – so I coded a simple shortcode for you all! You can use this shortcode for different goals. For example, you might want to display what products you’ve sold to enhance customer trust / social proof. So let’s see (1) […]
  • WooCommerce: Recently Viewed Products (Shortcode)
    Currently, you can use a widget or a block to have the user see the list of products they recently viewed. But for now, let’s create our own shortcode… and let’s take advantage of the existing Business Bloomer ClubRated 5.00 out of 5 $9.00 – $599.00 /once Whether you’re only starting with WooCommerce or you’re […]
  • WooCommerce: Exclude Category from ‘product_categories’ Shortcode
    Sometimes solutions are very simple, and you don’t need rocket science to fix your issue! A client of mine needed to hide a category from the Product Categories Shortcode ( BloomerArmada (1) WooCommerce Mini-Plugins (27) ); in fact, there is no parameter that allows you to “exclude” a given product category such as “uncategorized” or […]
  • WooCommerce: Display Product Reviews @ Custom Page (Shortcode)
    WooCommerce product reviews shows by default in the “Reviews” tab in the single product page. But what if, like me, you’re using custom sales pages and need to show such reviews elsewhere – by using a shortcode? I’ve spent some time doing this for two Business Bloomer pages, the contact page (beside the request a […]
  • WooCommerce: Check If User Has Purchased Product
    If you need to detect if a logged in user has purchased a certain product ID, this snippet will do the trick. You can use this for marketing (e.g. “Buy More of This!”) or for displaying special notices on the loop or the single product page. Enjoy!

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

190 thoughts on “WooCommerce: Display All Products Purchased by User

  1. Not working anymore, I added this code, I have latest Woocommerce. Please help to fix it. In debug.log I don’t see any errors.

    1. This is even compatible with HPOS, so it could be anything on your custom setup that is messing with it? Can you try on a clean install with only Woo active please?

  2. Hi, Came across this brilliant bit of coding and it works amazingly. Thank you. Just wanted to know if a customer ordered the wrong item on the original order. Can I delete it from recent products so they won’t order it again by mistake? Thanks again.

    1. Hello Dan, thank you for your comment. I think if they ordered the wrong item, you probably marked the item as “returned” within the order? If that’s the case, the item won’t show inside the “previously purchased” items.

      Otherwise, there is always a workaround e.g. a custom code to let you exclude certain products from certain users, 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!

  3. Is there a way to add below the shortcode [my_purchased_products] a second shortcode with cross-sell products?
    There are products where first order was for main product, like a printer, and when the client returns just needs to purchase consumables like the ink.
    Is it possible?
    Thank you very much.

    1. Is it possibl to add both?
      [my_purchased_products]
      [crossell_to_my_purchased_products]

      1. Yes of course, 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!

  4. Hello,
    This code works well on my website,
    Just want to know how we can show a custom message if the user doesn’t have any purchases.
    thanks

    1. Hi Vikas, 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!

  5. I just want to show the sum of the total purchased product per user ( for example user>1 purchased 10 products i want show “Total purchased products=10”) can you help me please

    1. Hi Muhammad, 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!

  6. thanks for the code you built. it works perfectly.
    Rightly if I click on the product image it opens me the product page. If the product is a downloadable file (like an ebook), is it possible to create a link to start the download by clicking on the product image? only in this case in which the user has already bought the product.
    thank you

    1. Hey Marco 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!

  7. I added the code to the bottom of functions.php

    Added the shortcode [my_products] to My Account Page which already had the shortcode [woocommerce_my_account].

    When that didn’t work I removed the [woocommerce_my_account] shortcode and just used [my-products] shortcode on My Account Page and that didn’t work either.

    I have both shortcodes on My Account page and All Products Purchased by User do not show up.

    1. Hey there, that won’t be the correct place to add this shortcode. Where exactly do you wish to display the products?

  8. I tried to use the code, I did all the steps.
    And yes, I tried to turn off all plugins as you wrote above, but nothing happens.

    1. Sorry. You’re definitely logged in with a user who purchased at least one published, visible product?

  9. Muchas gracias probΓ© el cΓ³digo y funciona a la perfecciΓ³n

  10. Hi Rodolfo,

    Thanks for your code. I followed all the steps but on my account page I just see the shortcode [my_purchased_products] and not the purchased products. The user I’m testing with has logged in and even purchased a product

    I added shortcode in div as mentioned below on the my account page
    [my_purchased_products]

    Please suggest.

    1. Hi Jenny! Did you change anything in my code?

  11. How can we limit to show only last 4 ordered products ?

    1. Hi Aman, 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!

  12. Hi!
    Thank you for your code! I put this in a website using Woocommerce 5.0.0 and Storefront, but it never works…

    1. Ciao Simona! Try with this revised version

  13. Is there a way to display the Categories that have been purchased as well as the products. This snippet has been really helpful!

    1. Hi Conan, 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!

  14. Hi Rodolfo, Thanks for your code. I would really appreciate it if you could assist me with this. I would like to display the Thumbnail of the item, Brand, Outfit type, Price (at which the product was sold at/bought by), Status (on hold/processing/completed). How can I amend the code to show these attributes? Thanks a ton!

    1. Hi Danish, 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!

  15. Hi Rodolfo.

    I love your snippets. Thanks from all of us.

    This snippet displays all purchased products in grid view only?

    Id like to have them displayed in list view instead.

    Any help would be greatly appreciated.
    Thanks
    Max

  16. Hi, this snippet lists the items in canceled orders (not completed) too.

    How can we list only the products from completed purchases?

    Thanks

    1. 'post_status' => 'completed'
      
      1. Hi Rodolfo ,
        Thanks for the great and useful snippet,
        I’m trying to display only completed orders and my code is :

        // GET USER ORDERS (COMPLETED + PROCESSING)
            $customer_orders = get_posts( array(
                'numberposts' => -Ϋ±,
                'meta_key'    => '_customer_user',
                'meta_value'  => $current_user->ID,
                'post_type'   => wc_get_order_types(),
        		'post_status' => 'completed',
                'post_status' => array_keys( wc_get_is_paid_statuses() ),
        		
            ) );
        

        I have added : ‘post_status’ => ‘completed’, but I still see all the orders, canceled encluded.

        What am I missing?

        1. Remove the other ‘post_status’

          1. Hi, adding this ‘completed’ line and removing the other did not work for me. It still shows all orders.

            // GET CURR USER
            $current_user = wp_get_current_user();
            if ( 0 == $current_user->ID ) return;
               
            // GET USER ORDERS (COMPLETED + PROCESSING)
                $customer_orders = get_posts( array(
                    'numberposts' => -1,
                    'meta_key'    => '_customer_user',
                    'meta_value'  => $current_user->ID,
                    'post_type'   => wc_get_order_types(),
                    'post_status' => 'completed',
            ) );
               
            // LOOP THROUGH ORDERS AND GET PRODUCT IDS
            if ( ! $customer_orders ) return;
            $product_ids = array();
            foreach ( $customer_orders as $customer_order ) {
                $order = wc_get_order( $customer_order->ID );
                $items = $order->get_items();
                foreach ( $items as $item ) {
                    $product_ids[] = $item;
                }
            }
            $product_ids = array_unique( $product_ids );
            $product_ids_str = implode( ",", $product_ids );
               
            echo $product_ids_str;
            
            1. My bad. It should be “wc-completed”

  17. Can you please update the code with the empty message if there is no product purchased. Thanks,

    1. Hi Penny, I can’t at the moment. Where it says:

      if ( ! $customer_orders ) return;

      … you can change that to:

      if ( ! $customer_orders ) {
         echo 'Your message';
      } else {
         // existing code
      }
      
  18. Wednesday, July 01, 2020.
    This snippet works perfectly. This article is so perfectly written I understood it without any difficulties and I’m not even a wordpress developer.

    Just 1 question from author. how can I add my own custom button to show when I hover the product?
    any help will be appreciated.

    Thanks for the snippet

    1. Hey Swapnil, 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!

  19. I tried it and works perfect. The only issue is that the snippet put in a second div bellow the initial and as per this, product list is shown bellow the sidebar and not bellow account info as shown in the screenshot.
    Am I missing something?
    I am using Storefront template.

    1. You could maybe wrap the output inside another DIV with a different display setting?

  20. Hi
    Is it possible to add orders list (that can be reached through orders tab) in Dashboard?

    1. Hi Amin, 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!

  21. seem like, it doesn’t work with woocommerce 4.

    I test on it and It’s not show anything to me just the blank template.

    1. Hi Sam, if you downgrade to Woo 3.9 does it work? I don’t see why it shouldn’t work with 4.0, it was not a major frontend change

  22. Hi, love your code and I am just wondering if I can display only products from specific order not products from all orders?

    Thanks in advance πŸ™‚

    1. Hi Martin, 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!

  23. Hi,
    this is great !
    By the way i would need to get only Products from a specific category Purchased by a User.
    Could someone help me to do that please ?
    thanks

    1. Hi there, 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!

  24. hi
    is there a way we can include the “hidden” or “private” products ? we need to display products from the old catalog only in the endpoint and not anywhere else on the site
    thanks

    1. Moe, 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!

  25. Hi Rodolfo,

    Is it possible to create a shortcode based on the who created the product? For example, I want to display x number of product created by me on a specific page.? I know what you created is slightly different but I’m looking to just show based on the current user who submitted the product.

    1. Hi Tony, 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!

  26. Thanks for the code. It works well, but how can we display a message when the customer has not yet purchased any products? It looks silly if you add a Title above the Shortcode, but there’s nothing being displayed.

    1. Hi Miguel, 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!

  27. Hi Rodolfo! I’m wondering if we can use this code to display purchased products that the user have not yet reviewed. Thanks!

    1. Hi Charmaine, 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!

  28. How can we detect 5 completed order (Products) by a particular user in woocommerce & notify them to admin?

    1. Hi Sourabh, 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!

  29. Thanks for this piece of code. it is working.

    only thing is that it is getting visible at the bottom of my account page after all the menu option and not the like the pic.

    1. That’s probably because you added it to the My Account WP page, correct?

    1. Great

  30. Hi Rodolfo.. Your post have been really helpful to me.. One thing I would like to know. Is there a way or snippets that let me add user avatar in the My Account page?

    1. Hi Schweizer, 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!

  31. Hi! I am trying to show some statistics for the customer where the user can filter at least per date and see what products where bought when and how much was also spent… per week/month/year etc. As I already saw, there is quite nothing similar about this. Where could I find some documentation about all the possible functions etc?.
    I guess it is quite hard to do this from scratch

    1. Javier, 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!

  32. Works perfectly !! Thank you for share. (WooCommerce Version 3.7.0). I did not place the shortcode ([my_purchased_products]) at first, I guess I thought it will show up magically where I wanted. I placed it on the dashboard as the example shows.

    1. Great!

  33. Hey

    It was not working first but when i changed shortcode name and now its working though add to cart and add to basket are not working properly. Thank you for sharing code.

    1. Hi Rutvi, I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  34. Any though on making this into a plugin? I can’t get it to work but I’d pay for it as a plugin for sure.

    1. Hey Jason, 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!

  35. Hi Rodolfo.

    Is posible to show the products only with the product image and title?

    1. Hello Gaizka, 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!

  36. Hi:
    The snippet is not working with the new woocommerce update.

    1. Works for me on Woo 3.6.3 πŸ™‚ Where did you place the shortcode?

    2. Very good work but sadly it doesnt work for 3.6.4 anymore. I followed exactly your instructions but dont know, it doesnt show any errors but also nothing.
      Do you have any idea?

      1. I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

        To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

        Hope this helps!

        R

  37. I added above code into functions.php. While updating the file I am getting the error as :

    “Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.”

    I searched on google regarding this but didn’t get answer. Can you help me regarding this.

    Thanks

    1. Hi Mangesh, 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. Thanks a lot for your understanding! ~R

  38. I need to display the products in the sidebar. I added the shortcode in the custom HTML widget, but its not working.

    1. Was the user logged in?

  39. hello,

    Code is working on latest wordpress + woocommerce (april 2019) but it also shows products on /my-account/ page of unlogged users.

    Can you test it please ?

    This is not a cache problem as I have excluded /my-account/ page from cache.

    Any help ?

    Thanks a lot.

    1. Hi there πŸ™‚ Where did you put the shortcode in?

  40. I want to remove the price and add to cart button. So the products would be displayed alone.

    1. Hello Buluro, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  41. Great post. For some reason the number posts is being over written. No matter what I put it only returned 10 results. I did a var dump and found this line:

    ‘request’ => ‘SELECT SQL_CALC_FOUND_ROWS wp….. ORDER BY wp_posts.post_date DESC LIMIT 0, 10’,

    The only way I was able to change this was to change the blog posts per page under ‘Reading’ in settings. I know there has to be a better way but this is all I got for now.

    1. Hey Chris, it must be another plugin or setting. This snippet usually returns “-1” products i.e. all of them

  42. I copied the code to themes function (function.php) via wordpress editor but there’s a syntax error on lines of:

    global $product, $woocommerce, $woocommerce_loop;

    woocommerce_product_loop_start();

    woocommerce_product_loop_end();

    woocommerce_reset_loop();

    saying “syntax error, unexpected ‘<', expecting variable (T_VARIABLE) or '{' or '$'"
    I'm no coder and havent got any idea how it went wrong and how to fix it

    1. Hello Nikka, thanks so much for your comment! Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~

  43. Great plugin, thank you!
    I was wondering if there was a way to display only the products that are NOT purchased by the user?
    (It would be a great way to increase sales, if users could see what products they bought, and what is still there to buy.)

    1. Hello there, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  44. Doesn’t this show other products when

    $product_ids

    is empty? In my case it does. For the other cases, it works fine but when the user hasn’t bought any products it just displays some random products. problem comes because of

    post__in

    . refer the following stackoverflow post https://stackoverflow.com/questions/23247671/wordpress-query-showing-post-in-empty-post-in-array

    So I suggest you do the following

    if(!empty($product_ids){
        //loop through the products
    }else {
        return "<div>When you have bought products it will appear here.</div>"
    }
    
    1. Fantastic, thanks for that!

    2. Correct code:

      if(!empty($product_ids)){
              echo do_shortcode('[my_purchased_products]');
          }else {
              return "<p>Aqui irΓ‘ aparecer as compras que vocΓͺ realizou.</p>"
          }
      
      1. Forgive me, i forgot to use ; in ‘else’ condition.

        function recent_purchases_content() {
            echo '<h4 class="block-header">Produtos recentes adquiridos na loja</h4>';
            if(!empty($product_ids)){
                echo do_shortcode('[my_purchased_products]');
            }else {
                return "<p>Aqui irΓ‘ aparecer as compras que vocΓͺ realizou.</p>";
            }
        }
        add_action( 'woocommerce_account_dashboard', 'recent_purchases_content' );
        
        
        1. Hey Jorge…

          I am using your solution but no products are displayed.
          When I add the shortcode directly to the page in the back end, then the products display nicely. But when I add your solution, to the functions.php file, nothing is shown.

          Do you think you could help?

          Thanks so much.

  45. works like charm, thank you.
    I had a problem with a theme which made conflict and I see [my_products] in the account page. but with your snippet I could see really my products.
    Many thanks

    1. Brilliant!

  46. I want to display just few products, lets say 6 products. And have a link to view all the purchased product.

    1. Hello Anamol, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  47. Hello – I am not able to get the shortcode to work _ Theme X Pro

    1. It should work now πŸ™‚

  48. Hi, thanks for this great code! πŸ™‚
    Just want to share how I solved if product are not showed, you need to remove:

    'posts_per_page' => -1

    Hope this help!
    Best regards,
    Simone

    1. Fantastic, thanks a million πŸ™‚

  49. Hi Rodolfo!
    Your snippet is great!!
    I need to adapt it so it shows the sold product by author, is this possible?

    Thanks!
    Carla.

    1. Thanks Carla πŸ™‚ Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution 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

  50. Hello!
    How to place that short code in one of the pages of “my account” of WooCommerce. This function could insert directly into “My Account” by default or how would it be using the shortcode?
    Regards

    1. Hello! Check this tutorial: https://businessbloomer.com/woocommerce-how-to-customize-the-my-account-page/ – hope this helps πŸ™‚

    2. Thank you, but It’s not working for me in the latest version of Wocommerce 3.4.7

    3. Works! I was forgetting to go edit my menu for woocommerce in appearances.

      1. πŸ™‚

  51. Hello Thank you so much for this amazing code
    I am getting an error:

    Line 34: ‘post_type’ => ‘product’,
    35 ‘post_status’ => ‘publish’,
    36 ‘posts_per_page’ => -1

    our PHP code changes were rolled back due to an error on line 34 of file wp-content/themes/astra-child/functions.php. Please fix and try saving again.

    syntax error, unexpected ‘=’, expecting ‘)’

    1. Kevin, thanks for your comment πŸ™‚ I’ve revised the snippet, try again πŸ™‚

    2. Thank you so much –
      I have added the code in my childs functions.php and added the shortcode to the desired page.
      When I do this your shortcode is the only item that renderes on the site – if i remove the shoertcode all other content comes back – I am more than happy to pay for your service as this is a need I need.
      I reached out to Bryce at metorik.com because i love how this works on his platform and he informed me that you are a metorik.com user as well πŸ™‚ . Wow love that platform – is there any way we can connect?
      Thank you kindly

      1. Thanks for your comment Kevin – I just got back to you via email as per your request. Cheers πŸ™‚

  52. Rodolfo, I am using the Storefront theme w/only the plugin for Woocommerce enabled. I added your snippet to the functions.php, added the shortcode to the My Account page, then logged in however I’m not seeing any orders. The account I logged in has plenty of orders, albeit refunded and I’m running PHP 7 and up to date w/Wordpress and Woocommerce. Any suggestions on getting this to work?

    1. Hey Jonathan – thanks so much for your comment! This snippet will only consider “completed” and “processing” orders πŸ™‚

  53. Hello Rodolfo,
    I am writing to ask for your service and support.
    I have a website i am working on. But the stage i am now i need expert support on woocommerce and reporting/statistics.
    Where can i send you my detail request by email?
    I want to send you my request so you can do the review and give me some quote.
    I will be grateful to know where i can direct this.

    1. Hey Lenu, thanks so much for your comment! If you’d like to get a quote, feel free to contact me here. Thanks a lot! ~R

  54. Hi,
    Thanks for the article , it is very helpful and interesting. i am have some difficulties writing the sql command to display the all the product purchase by a user. can you help me with the SQL command to display all the products purchase by a user?

    1. Hi Giddeon, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  55. Hi. First, thank for this code.
    But, I have a problem with this. DonΒ΄t work for me.. Show me fatal error on line 6079 :

    add_shortcode( ‘my_products’, ‘bbloomer_user_products_bought’ );

    Can u help me please?

    1. Hey there, thanks for your comment! What does the fatal error say? Syntax error?

  56. Hello Rodolfo! Thank you for the great resource you are for the WooCommerce community.

    I’m running WP 4.9.7, WC 3.4.3, Genesis 2.6.1 and child theme Executive Pro 3.2.3, PHP 7.0.30-0ubuntu0.16.04.1– and cannot get products to display. The logged in customer has a completed order.

    I’ve added the shortcode [my_products] to the My Account page and the .php to the child theme’s functions.php file.

    When I remove the php, the shortcode shows up as plain text, with the php added, the shortcode disappears.

    Any assistance would be greatly appreciated.

    1. Hey Brian, thanks so much for your comment! This works for me, so please check if the product is “visible”, “published” and if the order is completed/processing. Let me know!

    2. Hey Rodolfo,

      I have experienced the same problem as Brain, I am on WordPress 4.9.7 using the DIVI theme, WC Version 3.4.3, I have added php snippet on the DIVI child theme function.

      I checked using the inspector that the inspector on the Front end a HTML is generated with the class “woocommerce columns-3” but the products inside it are empty.

      If you could please check and let use know would really appreciate

      1. Hey Nandip – try switching theme for a moment and disabling all plugins but WooCommerce. Does it work in this case? If yes, you have a plugin/theme conflict

  57. Hello,

    I update my WooCommerce to 3.4.2, Suddenly the product I purchased it doesn’t show now on my Account page.
    Basically I update also the code which is the latest compatible to 3.4.2 but still it doesn’t show.

    Any thoughts?

    Thank you.

    1. Works for me on 3.4.2 Alvin πŸ™‚

  58. Hi,

    Firstly thank you for creating this amazing resource, I think I implement your codes and learn from this site daily!

    Unfortunately this code doesn’t seem to be working for me? I have Woo3.3.5, WP4.9.5, Flatsome Theme, PHP 7, and can’t see any obvious red flags in the system report. Adding this functionality isn’t a priority but if someone finds a potential issue/fix let me know πŸ™‚ I’ll continue trying to work it out myself when I have time!

    Thanks again, Liz

    1. Hey Liz πŸ™‚ I just retested it on Woo 3.3.5 and it works. Try switching theme for a moment and see if the snippet applied to another theme works. It could be that Flatsome requires some customization of such snippet, and this could be a way to understand this. Let me know

  59. Brilliant, now do you know a way to connect this to the order form, so that a returning customer about to make a purchase would be warned they already bought this? Ideally if I could also insert a link to their Orders history it would be great.

    thanks!

    1. Hey Andre, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  60. Thank you SO much! This is exactly what I was looking for! I was wondering though, Is there any way to modify the code to remove the price and ‘add to cart’ button since they have already purchased the products?

    Thanks so much in advance!

    1. Hello Philip, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

    2. just add this css code in your my_account page to hide the price

      .woocommerce ul.products li.product .price, .woocommerce-page ul.products li.product .price {
      display: none;
      }

  61. Hiya,
    Looks like this “smart” dude copy-pasted everything without changing even a bit, lol: smarterdevs.com/woocommerce-add-wp-menu-wc-pages-via-php

    1. Eheh thanks Nazar πŸ™‚ I love when people copy me, it’s a good sign!

  62. Worked great! Thank you very very much! You are amaizning πŸ˜€

  63. Hi Rodolfo,
    First I want to thank you for all your information, tips and snippets, they’re very useful! I learned a lot through your site!

    I used this snippet, but I only got 2 products in stead of all purchased products. I took me a long time searching and trying to change your snippet, but then I found this snippet too: https://www.codesd.com/item/woocommerce-list-all-the-products-previously-ordered.html

    That one works for me!

    1. Mieke, thanks for that! You can simply remove the “posts_per_page” thing in my snippet and see if it works πŸ™‚

    2. After testing I had the same issue, used your suggestion and fixed it too. πŸ™‚ Thank you Mieke

  64. O correto Γ© ser feito assim:

    $customer_orders = get_posts(array(
    			'numberposts' =&gt; -1,
    			'meta_key'    =&gt; '_customer_user',
    			'meta_value'  =&gt; get_current_user_id(),
    			'post_type'   =&gt; wc_get_order_types(),
    			'post_status' =&gt; array('wc-completed', 'wc-processing'),
    		));
    

    Do jeito que vocΓͺ fez, consome muito o servidor , Γ© uma lΓ³gica de amador pegar todos os produtos.

    1. Hey Marcelo, thanks so much for your comment! Given that according to you my version uses a lot of memory, can you please post the whole revised snippet here? Thank you in advance!

    2. Marcelo, estou procurando fazer a mesma coisa em uma das minhas lojas, mas como o Rodolfo pediu, seria muito legal se vc pudesse compartilhar o snippet completo com as suas correçáes. O que acha? Valeu, abraço!

  65. Hi, Its not working on my side. Did exactly the same thing but not working πŸ™

    1. hey Jerina. I just retested this again on Woo 3.2.1 and Storefront theme and it still works. There must be something else on your end but I’m afraid I can’t help with custom troubleshooting here via the comments.

      To troubleshoot, go to WP Dashboard > WooCommerce > System Status: what errors do you see in red font?

      Also, take a look at this tutorial to see how to troubleshoot: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/

      Finally, can you try switching temporarily to “Twentyseventeen” or “Storefront” theme and let me know if it works?

      Hope this helps!

      R

    2. Thank you very much for your answer. I have tested on Twentyseventeen still not see anything. And I don’t see any error in System status. All are fine.

      I don’t why this is not working.

      1. Uhm, let’s see πŸ™‚ Are you on PHP 7?

  66. Hello and thanks
    in my case the code does not work does not return any results even if the user has completed the purchases, I tried with the store store and WooCommerce 3.1.2 shop can you help?

    1. Hey Marvy πŸ™‚ I just retested this again on Woo 3.1.2 and it still works. There must be something else but I’m afraid I can’t help with custom troubleshooting here via the comments. Thanks for your understanding πŸ™‚

  67. Is there a way to limit this to a specific category?

    1. Jonathan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  68. Hi, i follow your instruction and it’s not working ;(
    i tried using [my_products] on page and echo do_shortcode(‘[my_products]’);

    Please help.. thanks

    1. Jmarck, thanks for your comment! Were you logged in with a user who purchased some products?

    2. I agree, i am also not seeing anything and i am logged in as someone who purchased.. is this only for php 7, maybe because i am still using 5 it doesn’t work?

      1. What WooCommerce version are you guys using?

  69. Just wanted to say thanks. This worked great! I appreciate you sharing.

    1. Brilliant, thanks Justin πŸ™‚

  70. This isn’t working for me neither, I have the WOO 3.1.2, have you checked the snippet on this version?

    1. Yep Manny, just tested again, it works on Woo 3.1.2. Products must be visible and in the catalog in order to show, maybe you need to play with the ‘meta_query’ part πŸ™‚

  71. Good afternoon and thank you for this advise – should this still work for the latest Woo? Only say this because I have inserted the code exactly how is instructed and on my ‘completed orders’ account page it displays nothing.

    First I made sure orders had been completed.

    Then I inspected the code generated and I can see:

    but thats it

    any advise? Thank you

    1. Sorry – the code is:

      <ul class="products"> </ul>
      1. Are you logged in with the user who purchased those products?

    2. Sorry Rodolfo I did not see you had commented – yes this use has 2 completed orders but nothing is displayed on the [my-products] page. I can see in the code it displays this:

       <div class="woocommerce-MyAccount-content">
      <div class="woocommerce columns-3">
      <ul class="products"> </ul>
      </div>
      </div>

      So it is generating something…. Any advice? Thank you

      1. Jason, thanks for your comment! Are products “visible” in the shop? Otherwise I don’t know – it works on my test site. Try taking a look at this tutorial to see how to troubleshoot: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/

  72. Hi Rodolfo!

    Quick question, would you know how to output another text/link if the user hadn’t purchased anything?
    Or would this be more of a customization question.

    -Joshua

    1. Hey Joshua, thanks for your comment! Yes, this goes beyond the snippet specs, so I’m afraid I can’t help here πŸ™‚

  73. Hi Rodolfo,

    I inserted the php function in functions.php and the shortcode in the My account page but on the frontend i only view the shortcode…

    [my_products]

    please help!
    Davide

    1. Hey Davide, thanks for your comment! Weird πŸ™ Have you changed anything in the snippet?

  74. I just love Business Bloomer, i just love your teaching method i wish you were my teacher in university. Your articles are just amazing i have learned too much from you, your’s articles and Business bloomer.

    1. Thank you Danish… I love your comment πŸ™‚

  75. Hi,
    Do you have any update for Woocommerce 3.XXX??
    We just tested this code, but I think need some changes?
    Any update?

    1. Hey Marco, I just tested it on 3.0.4 and it works πŸ™‚

  76. Hello it works but i only want to show this in my account dashboard. How is that possible because placing the shortcode in my-account page displays it in all pages linked to my account i.e. in order page, edit address page, and even when user log outs the heading is shown in the login page yet. So i only want the products bought to be displayed in Dashboard of my account page.

    1. Hey Sarvesh, thanks for your comment! Try using this guide https://businessbloomer.com/woocommerce-visual-hook-guide-account-pages/ and identifying the correct hook πŸ™‚

      1. i am abit new to php so it woild be a grt help if u could guide how to use this in woocommerce_account_dashboard only

        1. Sarvesh, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Hopefully I will have time to create a snippet soon πŸ™‚ Thanks a lot for your understanding! ~R

  77. Hi Rodolfo,

    This also doesn’t work on my client’s site.

    I added the snippet to functions.php and [my_products] shortcode to the My Lessons page. Nothing appears in .

    I tested it with a test purchase using PayPal Sandbox, and with a free product (which also goes through checkout). Neither show up.

    I was using a different script to achieve the same thing, but this seemed to break after I updated Woocommerce to 3.0. Perhaps the update also affects your script?

    I am trying to use this script to display online music lessons purchased on this site on a page called My Lessons. I am using a plugin WooCommerce PayPerView to replace the product page content with the lesson content (embedded video and audio clips and links to PDF files). So when a customer (student) clicks on the product (lesson) title or thumbnail, they are taken to the product page, which now displays lessons content.

    Getting your script to work would make this possible. Thanks for your work!

    1. Hey Denis, thanks for your comment! Yes this is possible – when I update to Woo 3.0+ I will put this on my to-do list. Thank you! πŸ™‚

      1. It seems to work fine with Woo 3.0.6, and my theme is over two years old. When Woo 3 was released I had to replace a bunch of child files in my theme with the current ones… you might want to check WooCommerce System Status for any incompatible overrides if you haven’t tried that already.

  78. I added the code to the bottom of functions.php

    Added the shortcode [my_products] to My Account Page which already had the shortcode [woocommerce_my_account].

    When that didn’t work I removed the [woocommerce_my_account] shortcode and just used [my-products] shortcode on My Account Page and that didn’t work either.

    I have both shortcodes on My Account page and All Products Purchased by User do not show up.

    1. Hey Stacey, this works on my own website. Are you sure that particular User has purchased something?

    2. Stacey, any luck? I am having the same problem using Storefront theme and only the plugin Woocommerce enabled.

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 *