How to Check if a Customer Has Already Purchased a Product in WooCommerce

How to Check if a Customer Has Already Purchased a Product in WooCommerce
On this page
  1. Why Check Previous Purchases
  2. Step 1: Add the Purchase-Check Snippet
  3. Troubleshooting
  4. Frequently Asked Questions
  5. Conclusion

You can check if a customer has already purchased a product in WooCommerce using the built-in wc_customer_bought_product() function, which returns true or false for a given user or email against a specific product ID. It’s the standard way to show “you already own this” notices or trigger repeat-purchase marketing without querying orders manually.

Why Check Previous Purchases

  • Show a “buy again” prompt on the shop or single product page for consumables
  • Unlock content, downloads, or support access only for verified buyers
  • Avoid showing upsells for something the customer already owns
  • Personalize marketing emails based on real purchase history

Step 1: Add the Purchase-Check Snippet

The example below flags logged-in shoppers who already bought the item they’re currently viewing in the shop loop.

PHP
/** Show a "you already bought this" note under items in the shop loop */
add_action( 'woocommerce_after_shop_loop_item', 'flag_repeat_purchase_notice', 25 );

function flag_repeat_purchase_notice() {
    global $product;

    if ( ! is_user_logged_in() ) {
        return;
    }

    $already_bought = wc_customer_bought_product( '', get_current_user_id(), $product->get_id() );

    if ( $already_bought ) {
        echo '<p class="repeat-purchase-note">You bought this before — grab another?</p>';
    }
}
Check if a customer has already purchased a product in WooCommerce: the page before adding the code
Before
Check if a customer has already purchased a product in WooCommerce: the page after adding the code
After

Including “Processing” or “On Hold” Orders

By default, wc_customer_bought_product() only counts orders in a “paid” status (usually processing and completed). If your store holds pre-orders in “on-hold” for a long time, extend which statuses count as paid:

PHP
add_filter( 'woocommerce_order_is_paid_statuses', 'include_onhold_as_paid_status' );

function include_onhold_as_paid_status( $statuses ) {
    $statuses[] = 'on-hold';
    return $statuses;
}

Troubleshooting

Function Returns False for a Known Buyer

Check the order’s actual status — orders sitting in “pending payment,” “on-hold,” or “cancelled” won’t count unless you extend the paid statuses filter above.

Guest Checkout Purchases Aren’t Detected

Pass the customer’s email as the first argument instead of relying only on the user ID, since guest orders aren’t tied to a WordPress account.

Frequently Asked Questions

Does wc_customer_bought_product work for guest orders?

Yes, if you pass the guest’s email address as the function’s first parameter instead of leaving it blank.

Can I check for a purchase of any product in a category, not just one ID?

Yes — loop through the category’s product IDs and call the function for each, or query orders directly if you need category-wide detection at scale.

Does this check variations too?

Pass the variation ID instead of the parent product ID if you need to detect a purchase of a specific variation.

Conclusion

Checking if a customer has already purchased a product in WooCommerce is a one-line job thanks to wc_customer_bought_product() — just remember to account for guest emails and any non-default order statuses your store relies on.

See also How to Hide the Add to Cart Button If Already Purchased in WooCommerce. Then read How to Check if a Customer Bought a Product in the Last 90 Days in WooCommerce.

Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.

Leave a Reply

Schedule a call