Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Woocommerce protected products

Options
  • 12-03-2021 2:13pm
    #1
    Registered Users Posts: 155 ✭✭


    I recently did a woocommerce store where the client wanted to protect some clients and only sell them to approved users.

    The request was that users would have to be logged in to see certain products and the site owner would control registration, giving him control of who was approved. If you were registered you were approved otherwise you were not.

    I used a membership plugin and a restricted content plugin which worked ok. Non logged in users only saw a subset of the products. Now the client wants the protected products to be visible to all but only available to purchase to signed in users.

    Any thoughts on how this could be done?


Comments

  • Registered Users Posts: 6,490 ✭✭✭daymobrew


    Add code to hide the 'Add to cart' button for signed in users.
    It might be something like this:
    [PHP]<?php
    add_action( 'woocommerce_before_single_product', 'dcwd_logged_in_to_buy' );
    function dcwd_logged_in_to_buy() {
    if ( ! is_user_logged_in() ) {
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
    }[/PHP]

    You will have to do something similar for the product archives.


  • Registered Users Posts: 155 ✭✭dahayeser


    Thanks daymobrew, that would block all products to the non logged in user. The client is just looking to block the purchase of certain products. As I said I have done it with a membership plugin. The down side here is that guests don't see the full range of products.


  • Registered Users Posts: 6,490 ✭✭✭daymobrew


    dahayeser wrote: »
    Thanks daymobrew, that would block all products to the non logged in user. The client is just looking to block the purchase of certain products. As I said I have done it with a membership plugin. The down side here is that guests don't see the full range of products.
    That code only removes the 'Add to cart' button, it doesn't prevent people from browsing.

    To limit it to certain products I suggest creating a new category (if you can exclude it from showing at the front end) or a tag (if you don't show tags) and add code to check the product's category or tag.

    If you want to entice people to become approved customers then use the category option and call it something that will tempt users.


Advertisement