Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By azuokeke on
Please I am new to drupal. I wish to disable the 'add to cart' & 'add to wish list' buttons for all anonymous users but this would be reactivated on registering or login. On clicking either of these buttons prio to login, a dialog box would popup (not the drupal error string) saying 'login or new account required'. These obviously would returned to normal on login. An ideas or existing modules? Thanks.
Comments
.
Have you looked at the permissions (user settings/permission) for the ubercart module, to see if there is the possibility to disable permission for anonymous users to purchase products, even while they can still view them?
Ubercart add to cart button disabling
Thanks for your comments but I have check ubercart settings - the closest thing that can be done from the cart is the ensure anonymous checkouts which is not exactly what I want. I have found a module uc_disable_product which enables the 'add to cart' & 'wish list' buttons to be optionally disabled but this hides the buttons completely. What I would prefer is still see the buttons but on clicking either of them, a popup message would be shown to the user to register or login first. Even if the buttons are hidden, another button would still be shown that on clicking by the user to buy the product would still be shown the same message.
-
I wish I could help you -- it sounds like you need some javascript for the popup.
From my own experience, I have found that potential customers are -- generally speaking -- put off from purchasing something online if they have to go through the registration process first. Its the whole concept of instant gratification, which it seems to me the internet has certainly promoted.
Anyway, good luck.
Thanks for your comments.
Thanks for your comments. Would look more into a work around.
News?
One thing I thought of is that the 'Add To Cart' button would actually be a link to the regular login screen with a destination suffix to the 'add to cart' action. I do not want to 'invent the wheel' though, if there's already some solution out there.
Did someone make any progress on this one?
using rule to hide add to cart
I don't know how helpful this will be to you but thought I'd reply anyway.
I was able to use the rules module to hide the "add to cart". First you must enable form events ( you might also check display form element ids), then go to the product and activate the events for the "add to cart". When you create a new rule their will be new events for that "add to cart" id. For my purposed I was hiding the "add to cart" for certain roles so I uses the event for when the form was being built to hide but if you want to redirect you might try using the submit event or validate. From my understanding there are unique ids for each "add to cart" to avoid collision so you must do this for each product.
I also found there are module uc disable store,which could be used with rules to add a message with link or display a login block.
form alter
If you have a module you can do a form alter.
Another hook_form_alter
Another hook_form_alter solution, which removes the [Add to Cart] buttons on both the Product page and the Buy Now (catalogue list) page and tells the user up front that they need to login/register before shopping.
a little correction
just a little correction for the above solution (which works perfect)
Drupal 7
case 'uc_product_add_to_cart
case 'uc_product_add_to_cart_form_XXX':
How can I make this into sort of a wildcard statement so that it applies to all add to cart buttons? I can't figure out how to do that, since all of the add to cart button IDs include the node ID, and I need for this to apply to all products store-wide.
Some suggestions...
Posting some basic suggestions for those looking (too little info on the subject):
- Permissions > Roles (Anonymous) - uncheck the "Purchase products (Allow user to purchase products)", this is enabled by default
- Check that all related blocks (like the Shopping Cart) is disabled as well for Anonymous
- Try contrib modules such as Ubercart Disable https://www.drupal.org/project/uc_disable
Hope this helps!