Tips and Tricks HQ Forum

Support Forum for Tips and Tricks HQ Products

Register or log in - lost password?

Search the Forum

Tips and Tricks HQ Forum » WP eStore Forum

[Help] Restrict the use of "Add to cart" button only to registered user

(13 posts) (4 voices)
  • Started 2 years ago by altered_sunset
  • Latest reply from wpCommerce
  • Related Topics:
    1. Add to Cart Button and Buy Now Button issues: Not working at all.
    2. Displaying Multiple Selected Categories
    3. Fancy10 Lightbox First Image Linking
    4. Customize CSS HTML Elements
    5. Shipping Variation Option - Force update?

Tags:

  • registered user
  • restrict
  • show buy button to registered user
  • WP eStore
12Next »
  1. altered_sunset
    Member

    Regards to every one. Since a few days ago I bought the eStore plugin.
    I tried many similar plugins for wordpress, but this is what I was looking for.
    Now I'm trying to familiarize with it in order I should be able to customize it for my new template (actually work-in-progress in offline).

    Please, I would like to insert an user "check" function in order that only registered users (with the basic registration of wordpress form) can use the "Add to cart" function/button, and then redirect the "non-logged-in" and "non-registered" users to the Login-Register main page.

    In this simple way, I'll be able to show my e-Store shop to anyone, and allow to only thrusted users to buy from my site.

    I want to protect me more against fake orders/bots (I know that to perform a paypal payment, an user should have a paypal account).

    Is the "Add to cart" button function in the "wp_eStore1.php" file?
    How can I add the php "if" check with the "is_user_logged_in" wordpress function?

    Thank you in advance!

    Posted 2 years ago #
  2. amin007
    Key Master

    "I know that to perform a paypal payment, an user should have a paypal account" - this statement is not entirely true. If you don't have PayPal you can still make a purchase with credit card.

    Anyway, you should be able to achieve what you are after very easily. Search for the following function in the "eStore_misc_functions.php" file:

    function get_button_code_for_product($id)

    You can introduce your "is_user_loggged_in" check at the beginning of this function so if the user is not logged in you can show the "Log in" link rather than the button.

    Posted 2 years ago #
  3. altered_sunset
    Member

    Thank you very much!

    Posted 2 years ago #
  4. crowdis
    Member

    First of all thank you for this great efficient plugin. It works like a charm. I just had a similar customization problem as mentioned in this post. I need to restrict the use of the "Add to Cart" button to registered users only. And if someone is not logged in it would be nice to alternatively display a "Log In" button where the "Add to Cart" button normally is.

    I have gone to the eStore_misc_functions.php and have found the line of code like you described but I am myself not experienced in creating WP code. Could you help me with creating this short piece of code?

    Furthermore I would require that this "restrict to signed in user" function can be item specific so that not every product in the store is restricted to signed in users.

    I would really appreciate your help since I haven't managed to get anywhere with this problem in the last month.

    Thank you.

    Posted 9 months ago #
  5. amin007
    Key Master

    I can give you some guidance on what to do but essentially to be able to customize this to your hearts content you will need to have PHP skill (it is beyond my capability to get you up to speed on PHP).

    Please open the "eStore_misc_functions.php" file and look for the following function:

    function get_button_code_for_element

    once you find this function just add the following bit of code just inside the function.

    if (!is_user_logged_in())
    {
        $output .= "You must be logged in to purchase";
        return $output;
    }

    So after the modification it will look similar to the following:

    function get_button_code_for_element(........)
    {
        if (!is_user_logged_in())
        {
            $output .= "You must be logged in to purchase";
            return $output;
        }
        .....
        .....

    This will make it so the button won't get displayed to non logged in users. Instead it will display the "You must be logged in to purchase" message.

    If you are creating a membership site I think you will need a WordPress membership plugin. This will give you the ability to hide the button behind a protected page so only members can access the button and so on.

    Posted 9 months ago #
  6. crowdis
    Member

    I tried inserting the code the way you explained but it came up with an error. That's ok, there is only so much that you can help me with. Unless you are interested in doing some work on the side with this? (PM me if you are interested).

    The other thing you mentioned is the membership plugin, which I actually already have. I purchased the eStore and eMember plugin as a set and got both up and running. I just couldn't find any functionality in either plugin which would allow me to restrict non-members from purchasing certain products. Of course I can hide an entire page with products in it but that would mean that visitors won't be able to see what great products we have for offer. It's complicated because we are an alternative medicine clinic, and we cannot sell products to every person who walks in from the streets. Only clients.

    So if anything more comes to mind please let me know or PM me. Otherwise I will continue looking for someone on elance.

    Thanks.

    Posted 9 months ago #
  7. amin007
    Key Master

    If you have the WP eMember plugin then there is a really easy way to handle this.

    Simply go to the "WP eStore Settings" -> "AddOn Settings" and then check the "Only Logged In Members Can Checkout" field. This will make it so anyone can add items to cart but they won't be able to checkout unless they log in as a member.

    Posted 9 months ago #
  8. crowdis
    Member

    Well that would be a great way to solve my problem. I have checked "WP eStore Settings -> AddOn Settings" and all I have there is checkboxes for options concerning affiliate shopping. I have also searched the rest of the settings including the settings for eMember and did find the option.

    Maybe something to do with my version? I have eStore 3.6.2 and eMember 6.3.0. eStore was installed first then followed by eMember.

    The question is also - with the option that you have suggested will I be able to control the checkout for specific products? Unfortunately that is my big problem, I need to be able to control specifically what products can be bought by anyone and what products can be only bought by clients.

    Thank you for your feedback so far. It's really great.

    Posted 9 months ago #
  9. amin007
    Key Master

    "Cannot find the mentioned settings option" - Upgrading your eStore will help. You can get a new build of eStore from here:
    http://support.tipsandtricks-hq.com/update-request

    The way you have it setup it won't work actually. When you enable the "Only Logged In Members Can Checkout" option it will make it to where everyone has to be a member before they can checkout. Obviously you can let them be a free member but I don't think thats what you are after.

    What will solve your issue is if you get a custom shortcode developed that lets you place a product display for a particular membership level.

    Posted 9 months ago #
  10. crowdis
    Member

    Ok thank you very much. I will upgrade the eStore and check the "Only Logged In Members Can Checkout" option anyway so that at least I have a database of all buyers.

    That custom short code is also an excellent idea. That will be a much better way to do it then putting the "if function" in as shown earlier.

    One last question then: if I get someone to develop the short code, which .php file contains all the short code functions?

    Thank you very much, you have been a great help. I wouldn't know what to do without you. I will put the url for the finished shopping cart up on this post.

    Posted 9 months ago #

RSS feed for this topic

12Next »

Reply »

You must log in to post.

Tips and Tricks HQ Forum is proudly powered by bbPress

Tips and Tricks HQ  | WP Shopping Cart  | WP Affiliate Software  | WordPress Membership Plugin