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?
- Customer Convenience: Avoid confusing customers by showing only relevant purchase options.
- Streamlined Shopping: Simplify the product pages for returning customers.
- 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.
- Create a Child Theme (if you don’t already have one):
- Visit our Free WordPress Child Theme Generator to create and download your child theme.
- Follow the instructions to install and activate your child theme.
- Add Code to
functions.php:- Navigate to Appearance > Theme File Editor in your WordPress dashboard.
- Select the
functions.phpfile 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.
Use Cases for Hiding the Add to Cart Button for Purchased Products
- Subscription Products: Prevent customers from purchasing duplicate subscriptions.
- Unique Items: For stores selling unique or one-of-a-kind items, ensure customers don’t buy the same item twice.
- Seasonal Products: For products that are only relevant for a specific season or event, hide the purchase option once it’s no longer applicable.
- 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.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

