Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › [Help] Restrict the use of "Add to cart" button only to registered user
- This topic has 13 replies, 5 voices, and was last updated 12 years, 7 months ago by admin.
-
AuthorPosts
-
January 31, 2010 at 8:10 pm #727altered_sunsetMember
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!
January 31, 2010 at 9:52 pm #17639amin007Participant“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.
February 2, 2010 at 10:52 am #17640altered_sunsetMemberThank you very much!
April 26, 2011 at 11:05 pm #17641crowdisMemberFirst 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.
April 27, 2011 at 3:51 am #17642amin007ParticipantI 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.
April 28, 2011 at 4:08 am #17643crowdisMemberI 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.
April 28, 2011 at 4:58 am #17644amin007ParticipantIf 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.
April 29, 2011 at 1:05 am #17645crowdisMemberWell 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.
April 29, 2011 at 5:40 am #17646amin007Participant“Cannot find the mentioned settings option” – Upgrading your eStore will help. You can get a new build of eStore from here:
https://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.
April 29, 2011 at 11:58 pm #17647crowdisMemberOk 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.
April 30, 2011 at 4:13 am #17648amin007ParticipantIt will be a good idea to add this in the eStore’s extra shortcodes plugin (this way you are not modifying the core eStore plugin). You can add a new shortcode with the ability to have a fancy1 product display for a particular membership level. The implementation can go in the “eStore-extra-shortcodes.php” file.
May 5, 2011 at 8:49 am #17649crowdisMemberOk also I cannot find the “eStore-extra-shortcodes.php” file but I assume that is because I still have the older version of eStore. Now that I know how to update that I will get that fixed.
But basically so I can brief the .php programmer, they have to replicate one of the fancy display codes and place it into the “eStore-extra-shortcodes.php” file. Then just add an “if” statement which checks the membership level and displays the “Add to Cart” button only to signed in members.
May 6, 2011 at 12:05 am #17650wpCommerceModerator“eStore-extra-shortcodes.php” file is in the “eStore-extra-shortcodes” plugin folder(This is another plugin which enhances the features of eStore). You can download the plugin from here –
http://www.tipsandtricks-hq.com/ecommerce/wp-estore-shortcodes-and-functions-reference-460
April 14, 2012 at 1:39 am #17651adminKeymaster -
AuthorPosts
- You must be logged in to reply to this topic.