Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Woocommerce protected products

  • 12-03-2021 02:13PM
    #1
    Registered Users, Registered Users 2 Posts: 156 ✭✭


    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, Registered Users 2 Posts: 6,652 ✭✭✭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, Registered Users 2 Posts: 156 ✭✭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, Registered Users 2 Posts: 6,652 ✭✭✭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