title: Make a product to be purchased only once or not if any item from a specific product category has been purchased in Woocommerce
body: <p>In woocommerce, I am just using simple products and I have a special product "free trial package" from a product category "A", which I'm willing to:</p>
  
  <ol>
  <li><strong>let the customer only purchase this "free trial package" once</strong> … </li>
  <li><strong>if the customer buy other products from the same product category "A" first, then the customer can't purchase this "free trial package" anymore</strong></li>
  </ol>
  
  <p>This means the customer only be able to get the "free trial package" only if it's the first purchase of that product category "A".</p>
  
  <p>My code doesn't seem to work properly and it only do the 1st point. </p>
  
  <p>The other problem is that if the user order finishes, next time user open cart it shows a weird message:
  <em>"you cant select this product anymore, you already bought this package"</em>.It's like Woocommerce cache problem or something…</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>function sv_disable_repeat_purchase( $purchasable, $product ) {
      $non_purchasable = 190;
  
      $product_id = $product-&gt;is_type( 'variation' ) ? $product-&gt;variation_id : $product-&gt;id;
  
      if ( $product_id != $non_purchasable ) {
          $purchasable = true;
      }
  
      if ( wc_customer_bought_product( wp_get_current_user()-&gt;user_email, get_current_user_id(), $product_id ) ) {
          $purchasable = false;
      }
  
      if ( $purchasable &amp;&amp; $product-&gt;is_type( 'variation' ) ) {
          $purchasable = $product-&gt;parent-&gt;is_purchasable();
      }
  
      return $purchasable;
  }
  add_filter( 'woocommerce_variation_is_purchasable', 'sv_disable_repeat_purchase', 10, 2 );
  add_filter( 'woocommerce_is_purchasable', 'sv_disable_repeat_purchase', 10, 2 );
  </code></pre>
  
  <p>Any help is appreciated.</p>