News:

Looking for documentation? Take a look on our wiki

Main Menu

Hide Add To Cart button for non registered users

Started by discjockeyr, January 19, 2017, 16:04:34 PM

Previous topic - Next topic

discjockeyr

Hi,
I have a website with products that i want only the wholesale customers to see the prices so i have create a wholesale group and only registered users can access the prices. Non registered users can only see the products,
I want also to hide the option ADD TO CART from non registered users. Is there any way?

thanks

jenkinhill

Use template overrides edited so as to hide the prices and add to cart elements if the user is logged in (eg http://forum.virtuemart.net/index.php?topic=135893.msg473725#msg473725)
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

jjk

Quote from: discjockeyr on January 19, 2017, 16:04:34 PM
I want also to hide the option ADD TO CART from non registered users. Is there any way?

See https://docs.virtuemart.net/tutorials/templating-layouts/199-sublayouts.html

For hiding the 'Add to cart' button in the category views, adjust the file
your-root-folder\components\com_virtuemart\sublayouts\products.php

Find the following lines (approximately line 125)
<div class="vm3pr-<?php echo $rowsHeight[$row]['customfields'?>"> <?php
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop''addtocart'))); ?>

            
comment it (add //)  like this:
<div class="vm3pr-<?php// echo $rowsHeight[$row]['customfields'] ?>"> <?php
//echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row], 'position' => array('ontop', 'addtocart'))); ?>

            
and save it for example as products_less-cat-cart-btn.php
If you have a Joomla menu for your categories with the menu item type 'VirtueMart > Category Layout'' you can select the new sublayout at 'Menus: Edit Item ' > 'VirtueMart category view settings' tab from the dropdown list at 'Sublayouts for products in category'.

Removing the 'Add to cart' button from the product details page is pretty similar. The file to look at in this case is your-root-folder\components\com_virtuemart\views\productdetails\tmpl\default.php
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

discjockeyr


Studio 42

I think that it's better to do the overide in virtuemart/sublayouts/addtocart.php so it work directly for module too.
eg. add begin of file
<?php 
if(empty(JFactory::getUser()>id)) {
// echo "please login";
return;
?>

if you prefer you cann add a message too, if you uncomment the echo

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Rozie

Quote from: Studio 42 on January 20, 2017, 12:01:37 PM
I think that it's better to do the overide in virtuemart/sublayouts/addtocart.php so it work directly for module too.
eg. add begin of file
<?php 
if(empty(JFactory::getUser()>id)) {
// echo "please login";
return;
?>

if you prefer you cann add a message too, if you uncomment the echo

I just tried this fix and it takes away the 'add to cart' button fine but when I login the button doesn't show.  I added the code to the very begining of the file before the <?php is this correct?

I am using Joomla 3.8.3 and VM 3.2.12, I have 2 shopper groups, Guest (ID 1) for non-logged in viewers and Default (ID 2) for registered viewers I want the 'add to cart' button to show when users have logged in but not for non-logged in users.

I would be happy to pay for someone to do this for me if they have a fix and know of anyone who would help

Studio 42

Sorry a typo:
<?php 
if(empty(JFactory::getUser()->id)) {
// echo "please login";
return;
?>

Rozie

That works perfect, thank you so much for your help it is greatly appreciated.