Title: custom code caused conflict
Last modified: June 3, 2021

---

# custom code caused conflict

 *  Resolved [sydneywu](https://wordpress.org/support/users/sydneywu/)
 * (@sydneywu)
 * [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/)
 * Hi, I am using the following code so users have to log in to purchase products.
 * However, certain products (very randomly) still become non-purchasable for log-
   in users. This means the “add to cart” button is unable to click (login users).
   When this happens, I’ll refresh the page and then the “add to cart” button will
   work. How do I fix this problem?
 * Because I couldn’t find a way to hide the “add to cart” button for non-login 
   users on a product page. That’s why I am using the following code.
 * Hope anyone can help me, thank you.
 * add_filter(‘woocommerce_is_purchasable’, ‘my_woocommerce_is_purchasable’, 10,
   2);
    function my_woocommerce_is_purchasable($is_purchasable, $product) {
 *  $isLoggedIn = is_user_logged_in();
    if(true == $isLoggedIn){ //Make product 
   purchasable to logged in user return true; }
 *  //Make product not purchasable to unlogged in user
    return false; }
 * [https://glasslab303.com/wp-content/uploads/2021/06/purchasable.jpg](https://glasslab303.com/wp-content/uploads/2021/06/purchasable.jpg)
   
   [https://glasslab303.com/wp-content/uploads/2021/06/nonpurchasable.jpg](https://glasslab303.com/wp-content/uploads/2021/06/nonpurchasable.jpg)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Support [Gabriel – a11n](https://wordpress.org/support/users/gabrielfuentes/)
 * (@gabrielfuentes)
 * [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/#post-14518227)
 * Hi there 👋
 * Upon searching on the internet, I could find a custom PHP code that will allow
   you to hide the _Add to Cart_ button to non-login users. I’ve tried it and it
   worked great! Here is a direct link to the code:
 * [https://stackoverflow.com/a/59118057/15592226](https://stackoverflow.com/a/59118057/15592226)
 * After applying the code, it should look like this:
 * [https://www.screencast.com/t/woNYGOBVVr](https://www.screencast.com/t/woNYGOBVVr)
 * And, it looks like this when clicking on the read more button:
 * [https://www.screencast.com/t/As2mppVZ](https://www.screencast.com/t/As2mppVZ)
 * Also, you could use the **Catalog Visibility Options** plugin for this and much
   more!
 * [https://docs.woocommerce.com/document/catalog-visibility-options/](https://docs.woocommerce.com/document/catalog-visibility-options/)
 * Cheers! 🙂
    -  This reply was modified 5 years ago by [Gabriel - a11n](https://wordpress.org/support/users/gabrielfuentes/).
 *  Thread Starter [sydneywu](https://wordpress.org/support/users/sydneywu/)
 * (@sydneywu)
 * [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/#post-14518344)
 * Hi, thanks for the message.
 * I have tried the code.
 * This code seems to only work for single product (no variations). The “add to 
   cart” button did disappear when I am logout.
 * However, I also have products with variations, the “add to cart” button is still
   there.
 *  Plugin Support [Gabriel – a11n](https://wordpress.org/support/users/gabrielfuentes/)
 * (@gabrielfuentes)
 * [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/#post-14518446)
 * > However, I also have products with variations, the “add to cart” button is 
   > still there.
 * Yes, it shows the add to cart button for variations, but it doesn’t allow you
   to purchase the item. It will display a prompt _“Sorry, this product is unavailable.”_
 * [https://www.screencast.com/t/3QKBPlpVY](https://www.screencast.com/t/3QKBPlpVY)
 * Perhaps, there is some kind of conflict going on your site that prevents that
   the code works for the variable products.
 * Well, this is a fairly complex development topic. I’m going to leave it open 
   for a bit to see if anyone is able to chime in to help you out.
 * I can also recommend [the WooCommerce Developer Resources Portal](https://developer.woocommerce.com/)
   for resources on developing for WooCommerce.
 * You can also visit the [WooCommerce Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
   or the `#developers` channel of the [WooCommerce Community Slack](https://woocommerce.com/community-slack/).
   We’re lucky to have a great community of open-source developers for WooCommerce,
   and many of our developers hang out there, as well.`
 * If you do require more help with the actual coding, we’d recommend you hire a
   developer who can take a look at this, quote you for their services, and help
   you add this feature to your site. We’d recommend getting in touch with a web
   developer or one of the customization experts listed at [https://woocommerce.com/customizations/](https://woocommerce.com/customizations/).
 * Cheers.
 *  Thread Starter [sydneywu](https://wordpress.org/support/users/sydneywu/)
 * (@sydneywu)
 * [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/#post-14521409)
 * Okay, Thank You!
 *  Thread Starter [sydneywu](https://wordpress.org/support/users/sydneywu/)
 * (@sydneywu)
 * [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/#post-14538909)
 * solved.
 *  Plugin Support [Gabriel – a11n](https://wordpress.org/support/users/gabrielfuentes/)
 * (@gabrielfuentes)
 * [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/#post-14539221)
 * We are happy to help 😃
 * Great! If you have any further questions, you can start a new thread.
 * Cheers!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘custom code caused conflict’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Gabriel – a11n](https://wordpress.org/support/users/gabrielfuentes/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/custom-code-caused-conflict/#post-14539221)
 * Status: resolved