Disable Repeat Purchase Of Products

To disable repeat purchase of products using the `woocommerce_is_purchasable` and `woocommerce_variation_is_purchasable` hooks in WooCommerce, you can implement a custom solution that checks if the product or its variation is already in the customer’s order history. If so, the product will not be purchasable again. Here’s how you can achieve this:

Step 1: Check if Product is Already Purchased
Add the following code to your theme’s `functions.php` file or a custom plugin. This code checks if the product or variation is already purchased by the customer. If it is, the product will be marked as not purchasable.

 

function disable_repeat_purchase( $is_purchasable, $product ) {
    if ( $product instanceof WC_Product_Variation ) {
        $product_id = $product->get_parent_id();
    } else {
        $product_id = $product->get_id();
    }

    if ( wc_customer_bought_product( get_current_user_id(), get_current_user_email(), $product_id ) ) {
        $is_purchasable = false;
    }

    return $is_purchasable;
}

add_filter( 'woocommerce_is_purchasable', 'disable_repeat_purchase', 10, 2 );
add_filter( 'woocommerce_variation_is_purchasable', 'disable_repeat_purchase', 10, 2 );

 

Step 2: Test the Functionality
With the above code in place, products that the customer has already purchased will be marked as not purchasable. Customers will not be able to add the same product or variation to the cart again.

Please note that this code checks if the current customer (logged-in user) has purchased the product. If the customer is not logged in or does not have an order history, they will be able to purchase the product as usual.

Keep in mind that this approach might not be suitable for all scenarios, especially if you have guest users or customers who might want to repurchase products. Before implementing this functionality, consider how it aligns with your store’s specific requirements.

As always, thoroughly test the functionality to ensure it works as expected and does not interfere with other aspects of your WooCommerce store.

Related Blogs

WooCommerce: Check if Product Category is in the Cart

To check if a specific product category is in the cart during the `woocommerce_before_cart` action hook, you can use a similar approach as in the previous answer. However, in this case, you need to use the `woocommerce_before_cart_contents` action hook, which fires before the cart items are displayed on the cart page. Here’s how you can achieve this:

Request A Quote

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.