How to Hide Add to Cart If Already Purchased in WooCommerce – 2026

Last updated on August 2nd, 2024 at 12:34 pm

Enhancing the customer experience on your WooCommerce store can lead to increased satisfaction and repeat purchases. One way to personalise the shopping experience is by hiding the “Add to Cart” button for products that customers have already purchased. This guide will show you how to implement this feature without using any plugins.

Why Hide the Add to Cart Button for Purchased Products?

  1. Customer Convenience: Avoid confusing customers by showing only relevant purchase options.
  2. Streamlined Shopping: Simplify the product pages for returning customers.
  3. Encourage Exploration: Guide customers towards other products they haven’t bought yet.

Step 1: Adding Code to Your Theme’s Functions File

To achieve this, you’ll need to add custom code to your theme’s functions.php file. If you don’t have a child theme set up, it’s best to create one to ensure your customisations are not lost when the theme updates. You can easily create a child theme using our free child theme generator.

  1. Create a Child Theme (if you don’t already have one):
  2. Add Code to functions.php:
    • Navigate to Appearance > Theme File Editor in your WordPress dashboard.
    • Select the functions.php file of your child theme.
    • Add the following code snippet to hide the “Add to Cart” button for purchased products:
/*
 * Snippet: How to Hide Add to Cart If Already Purchased in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1344
* Tested with WooCommerce 10.7.0
* "Hide Add to Cart button if product already purchased"
*/ function wcsuccess_hide_add_to_cart_for_purchased_products() { if ( is_user_logged_in() ) { $user_id = get_current_user_id(); $purchased_products = wc_get_customer_order_items( $user_id ); foreach ( $purchased_products as $product_id ) { remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); remove_action( 'woocommerce_loop_add_to_cart_link', 'woocommerce_template_loop_add_to_cart', 10 ); } } } add_action( 'wp', 'wcsuccess_hide_add_to_cart_for_purchased_products' ); /* * * Snippet: How to Hide Add to Cart If Already Purchased in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1344
* Tested with WooCommerce 10.7.0
* "Get list of purchased products for customer"
*/ function wc_get_customer_order_items( $customer_id ) { $order_items = array(); $customer_orders = wc_get_orders( array( 'customer_id' => $customer_id, 'status' => 'completed', 'limit' => -1 ) ); foreach ( $customer_orders as $order ) { foreach ( $order->get_items() as $item ) { $order_items[] = $item->get_product_id(); } } return $order_items; }

Step 2: Test the Functionality

Log in to your WooCommerce store as a customer who has previously made a purchase. Navigate to the product pages of items you’ve bought and verify that the “Add to Cart” button is hidden. For products you haven’t purchased, the “Add to Cart” button should still be visible.

See also  How to Change Product Tab Titles and Headings in WooCommerce - 2026

Use Cases for Hiding the Add to Cart Button for Purchased Products

  1. Subscription Products: Prevent customers from purchasing duplicate subscriptions.
  2. Unique Items: For stores selling unique or one-of-a-kind items, ensure customers don’t buy the same item twice.
  3. Seasonal Products: For products that are only relevant for a specific season or event, hide the purchase option once it’s no longer applicable.
  4. Loyalty Programs: Encourage customers to try new products by hiding the “Add to Cart” button for items they already own.

Conclusion

Hiding the “Add to Cart” button for already purchased products can enhance the user experience on your WooCommerce store by providing a more personalised shopping experience. By implementing the code provided in this guide, you can easily hide the “Add to Cart” button for purchased products without the need for additional plugins.

See also  How to Change the Product Tabs Order in WooCommerce - 2026

0 0 votes
Article Rating

Stay In Touch

Was this post helpful? Why not show your support and buy me a coffee?

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top
0
Would love your thoughts, please comment.x
()
x
×