{"id":6959,"date":"2020-04-23T03:49:34","date_gmt":"2020-04-23T03:49:34","guid":{"rendered":"https:\/\/expertwebtechnologies.com\/?p=6959"},"modified":"2025-01-07T13:27:50","modified_gmt":"2025-01-07T13:27:50","slug":"woocommerce-disable-repeat-purchase-of-products","status":"publish","type":"post","link":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/","title":{"rendered":"WooCommerce :  Disable Repeat Purchase Of Products."},"content":{"rendered":"\n<h1>WooCommerce :  Disable Repeat Purchase Of Products.<\/h1>\n<div>\n<h3>Want to sell one product only once per user?<\/h3>\n<h3>Restrict User to buy a specific product only once in a lifetime from your WooCommerce site?<\/h3>\n<p>Some times in WooCommerce products we need to stop user from buying product multiple time, that means user can buy that product only once.<\/p>\n<p>Depending on what kind of products you selling from your WooCommerce online store, you may want to restrict your customers from purchasing a product more than once from your online store.<br>\nMay be want to disable repeat purchases for all products, or may be want to prevent repeat purchase of a specific product.<\/p>\n<p>For applying any restriction first we need to check that user has already bought that product or not after that we need to disable buying ability of user for that product.<\/p>\n<p>WooCommerce provide <b>woocommerce_is_purchasable<\/b> and <b>woocommerce_variation_is_purchasable<\/b> filter for setting restrictions to products.<br>\nwe can apply our conditional statements in it.Both <b>woocommerce_is_purchasable<\/b> and <b>woocommerce_variation_is_purchasable<\/b> returns true and false.<\/p>\n<p>And for checking user has already bought product or not we can use <b>&#8216;wc_customer_bought_product&#8217;<\/b> function.<\/p>\n<p>SO it&#8217;s a combination of two methods<\/p>\n<ol>\n<li><b>woocommerce_variation_is_purchasable<\/b> filter<\/li>\n<li><b>woocommerce_is_purchasable<\/b> filter<\/li>\n<li><b>&#8216;wc_customer_bought_product&#8217;<\/b> function<\/li>\n<\/ol>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"snip string\">\/\/ Disable repeat purchase of WooCommerce  products \/ WooCommerce variations<\/span>\n<span class=\"snip keyword\">function<\/span> <span class=\"snip function\">DisableRepeatPurchase<\/span>( $purchasable, $product ) {  \n&nbsp;&nbsp;<span class=\"snip string\">\/\/ Get ID for the current product<\/span>\n&nbsp;&nbsp;$product_id = $product-&gt;<span class=\"snip function\">get_id<\/span>();  \n&nbsp;&nbsp;<span class=\"snip string\">\/\/ return false if the customer has already bought the WooCommerce product \/ WooCommerce variation<\/span>\n&nbsp;&nbsp;if (<span class=\"snip function\"> wc_customer_bought_product<\/span>(<span class=\"snip function\">wp_get_current_user<\/span>()-&gt;user_email, <span class=\"snip function\">get_current_user_id<\/span>(), $product_id ) ) {\n&nbsp;&nbsp;&nbsp;&nbsp;$purchasable = <span class=\"snip keyword\">false<\/span>;\n&nbsp;&nbsp;} \n&nbsp;&nbsp;<span class=\"snip string\">\/\/check for variations: if parent is not purchasable, then variation is not<\/span>\n&nbsp;&nbsp;if ( $purchasable &amp;&amp; $product-&gt;<span class=\"snip function\">is_type<\/span>( 'variation' ) ) {\n&nbsp;&nbsp;&nbsp;&nbsp;$parent = <span class=\"snip function\">wc_get_product<\/span>( $product-&gt;<span class=\"snip function\">get_parent_id<\/span>() );\n&nbsp;&nbsp;&nbsp;&nbsp;$purchasable = $parent-&gt;<span class=\"snip function\">is_purchasable<\/span>();\n&nbsp;&nbsp;}  \n&nbsp;&nbsp;<span class=\"snip keyword\">return<\/span> $purchasable;\n}\n<span class=\"snip function\">add_filter<\/span>(<span class=\"snip string\">'woocommerce_variation_is_purchasable'<\/span>,<span class=\"snip string\">'DisableRepeatPurchase'<\/span>,<span class=\"snip number\">99<\/span>,<span class=\"snip number\">2<\/span> );\n<span class=\"snip function\">add_filter<\/span>(<span class=\"snip string\">'woocommerce_is_purchasable'<\/span>,<span class=\"snip string\">'DisableRepeatPurchase'<\/span>,<span class=\"snip number\">99<\/span>,<span class=\"snip number\">2<\/span> );\n<\/code><\/pre>\n<p>Paste this code to your theme&#8217;s functions.php.<br>\nAfter this if product in already bought by user the add to cart button is disabled.<br>\n<b>Note: If This product is already in cart then too no need to worry about it, it will automatically removed from cart page and checkout page.<\/b><br>\n<b>Note: This will add restriction for all product. for specific product we need to need conditional statement to check product id before applying restriction. <\/b><br>\nExample:<\/p>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"snip string\">\/\/ Disable repeat purchase of WooCommerce  products \/ WooCommerce variations<\/span>\n<span class=\"snip keyword\">function<\/span> <span class=\"snip function\">DisableRepeatPurchase<\/span>( $purchasable, $product ) {\n&nbsp;&nbsp;<span class=\"snip string\">\/\/ Enter ID of the product which must be restricted for purchasing again<\/span>\n&nbsp;&nbsp;$restricted = <span class=\"snip number\">1234<\/span>;  \n&nbsp;&nbsp;<span class=\"snip string\">\/\/ Get ID for the current product<\/span>\n&nbsp;&nbsp;$product_id = $product-&gt;<span class=\"snip function\">get_id<\/span>(); \n&nbsp;&nbsp;<span class=\"snip string\">\/\/Check product id with restricted product if true then restrict else return parent $purchasable value<\/span>\n&nbsp;&nbsp;if ( $restricted != $product_id ) {\n&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"snip keyword\">return<\/span> $purchasable;\n&nbsp;&nbsp;}\n&nbsp;&nbsp;<span class=\"snip string\">\/\/ return false if the customer has already bought the WooCommerce product \/ WooCommerce variation<\/span>\n&nbsp;&nbsp;if (<span class=\"snip function\"> wc_customer_bought_product<\/span>(<span class=\"snip function\">wp_get_current_user<\/span>()-&gt;user_email, <span class=\"snip function\">get_current_user_id<\/span>(), $product_id ) ) {\n&nbsp;&nbsp;&nbsp;&nbsp;$purchasable = <span class=\"snip keyword\">false<\/span>;\n&nbsp;&nbsp;} \n&nbsp;&nbsp;<span class=\"snip string\">\/\/check for variations: if parent is not purchasable, then variation is not<\/span>\n&nbsp;&nbsp;if ( $purchasable &amp;&amp; $product-&gt;<span class=\"snip function\">is_type<\/span>( 'variation' ) ) {\n&nbsp;&nbsp;&nbsp;&nbsp;$parent = <span class=\"snip function\">wc_get_product<\/span>( $product-&gt;<span class=\"snip function\">get_parent_id<\/span>() );\n&nbsp;&nbsp;&nbsp;&nbsp;$purchasable = $parent-&gt;<span class=\"snip function\">is_purchasable<\/span>();\n&nbsp;&nbsp;}  \n&nbsp;&nbsp;<span class=\"snip keyword\">return<\/span> $purchasable;\n}\n<span class=\"snip function\">add_filter<\/span>(<span class=\"snip string\">'woocommerce_variation_is_purchasable'<\/span>,<span class=\"snip string\">'DisableRepeatPurchase'<\/span>,<span class=\"snip number\">99<\/span>,<span class=\"snip number\">2<\/span> );\n<span class=\"snip function\">add_filter<\/span>(<span class=\"snip string\">'woocommerce_is_purchasable'<\/span>,<span class=\"snip string\">'DisableRepeatPurchase'<\/span>,<span class=\"snip number\">99<\/span>,<span class=\"snip number\">2<\/span> );\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>WooCommerce : Disable Repeat Purchase Of Products. Want to sell one product only once per user? Restrict User to buy a specific product only once in a lifetime from your WooCommerce site? Some times in WooCommerce products we need to stop user from buying product multiple time, that means user can buy that product only [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,35,36],"tags":[],"class_list":["post-6959","post","type-post","status-publish","format-standard","hentry","category-woocommerce","category-woocommerce-hooks","category-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WooCommerce : Disable Repeat Purchase Of Products. - EoXys IT<\/title>\n<meta name=\"description\" content=\"Learn how to disable repeat purchases of products in WooCommerce. Follow this guide to prevent customers from ordering the same product multiple times, improving inventory control and user experience.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WooCommerce : Disable Repeat Purchase Of Products. - EoXys IT\" \/>\n<meta property=\"og:description\" content=\"Learn how to disable repeat purchases of products in WooCommerce. Follow this guide to prevent customers from ordering the same product multiple times, improving inventory control and user experience.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/\" \/>\n<meta property=\"og:site_name\" content=\"EoXys IT\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-23T03:49:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-07T13:27:50+00:00\" \/>\n<meta name=\"author\" content=\"Shiv kumawat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shiv kumawat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/\"},\"author\":{\"name\":\"Shiv kumawat\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e\"},\"headline\":\"WooCommerce : Disable Repeat Purchase Of Products.\",\"datePublished\":\"2020-04-23T03:49:34+00:00\",\"dateModified\":\"2025-01-07T13:27:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/\"},\"wordCount\":298,\"commentCount\":0,\"articleSection\":[\"Woocommerce\",\"Woocommerce Hooks\",\"WordPress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/\",\"url\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/\",\"name\":\"WooCommerce : Disable Repeat Purchase Of Products. - EoXys IT\",\"isPartOf\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/#website\"},\"datePublished\":\"2020-04-23T03:49:34+00:00\",\"dateModified\":\"2025-01-07T13:27:50+00:00\",\"author\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e\"},\"description\":\"Learn how to disable repeat purchases of products in WooCommerce. Follow this guide to prevent customers from ordering the same product multiple times, improving inventory control and user experience.\",\"breadcrumb\":{\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eoxysit.com\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WooCommerce : Disable Repeat Purchase Of Products.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#website\",\"url\":\"https:\/\/eoxysit.com\/blogs\/\",\"name\":\"EoXys IT\",\"description\":\"Digitise your business\",\"alternateName\":\"Eoxys It\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eoxysit.com\/blogs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e\",\"name\":\"Shiv kumawat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png\",\"contentUrl\":\"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png\",\"caption\":\"Shiv kumawat\"},\"description\":\"\\\"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company\\\"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.\u201d\",\"sameAs\":[\"https:\/\/eoxysit.com\/\"],\"url\":\"https:\/\/eoxysit.com\/blogs\/author\/shivkumawat1985\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WooCommerce : Disable Repeat Purchase Of Products. - EoXys IT","description":"Learn how to disable repeat purchases of products in WooCommerce. Follow this guide to prevent customers from ordering the same product multiple times, improving inventory control and user experience.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/","og_locale":"en_US","og_type":"article","og_title":"WooCommerce : Disable Repeat Purchase Of Products. - EoXys IT","og_description":"Learn how to disable repeat purchases of products in WooCommerce. Follow this guide to prevent customers from ordering the same product multiple times, improving inventory control and user experience.","og_url":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/","og_site_name":"EoXys IT","article_published_time":"2020-04-23T03:49:34+00:00","article_modified_time":"2025-01-07T13:27:50+00:00","author":"Shiv kumawat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Shiv kumawat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#article","isPartOf":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/"},"author":{"name":"Shiv kumawat","@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e"},"headline":"WooCommerce : Disable Repeat Purchase Of Products.","datePublished":"2020-04-23T03:49:34+00:00","dateModified":"2025-01-07T13:27:50+00:00","mainEntityOfPage":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/"},"wordCount":298,"commentCount":0,"articleSection":["Woocommerce","Woocommerce Hooks","WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/","url":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/","name":"WooCommerce : Disable Repeat Purchase Of Products. - EoXys IT","isPartOf":{"@id":"https:\/\/eoxysit.com\/blogs\/#website"},"datePublished":"2020-04-23T03:49:34+00:00","dateModified":"2025-01-07T13:27:50+00:00","author":{"@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e"},"description":"Learn how to disable repeat purchases of products in WooCommerce. Follow this guide to prevent customers from ordering the same product multiple times, improving inventory control and user experience.","breadcrumb":{"@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/eoxysit.com\/blogs\/woocommerce-disable-repeat-purchase-of-products\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eoxysit.com\/blogs\/"},{"@type":"ListItem","position":2,"name":"WooCommerce : Disable Repeat Purchase Of Products."}]},{"@type":"WebSite","@id":"https:\/\/eoxysit.com\/blogs\/#website","url":"https:\/\/eoxysit.com\/blogs\/","name":"EoXys IT","description":"Digitise your business","alternateName":"Eoxys It","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eoxysit.com\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/534245eb0e092114ff5b6d0d877af61e","name":"Shiv kumawat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eoxysit.com\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png","contentUrl":"https:\/\/eoxysit.com\/blogs\/wp-content\/uploads\/2025\/03\/CEO-150x150.png","caption":"Shiv kumawat"},"description":"\"Shiv kumawat is the Executive Director and CEO of Eoxys It Solution LLP and the strategic mind behind the company\"s growth. His expertise in operational efficiency and team leadership empowers his colleagues to excel and innovate.\u201d","sameAs":["https:\/\/eoxysit.com\/"],"url":"https:\/\/eoxysit.com\/blogs\/author\/shivkumawat1985\/"}]}},"_links":{"self":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/posts\/6959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/comments?post=6959"}],"version-history":[{"count":0,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/posts\/6959\/revisions"}],"wp:attachment":[{"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/media?parent=6959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/categories?post=6959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eoxysit.com\/blogs\/wp-json\/wp\/v2\/tags?post=6959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}