VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: discjockeyr on January 19, 2017, 16:04:34 PM

Title: Hide Add To Cart button for non registered users
Post by: discjockeyr on January 19, 2017, 16:04:34 PM
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
Title: Re: Hide Add To Cart button for non registered users
Post by: jenkinhill on January 19, 2017, 16:31:03 PM
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)
Title: Re: Hide Add To Cart button for non registered users
Post by: jjk on January 19, 2017, 18:47:16 PM
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
Title: Re: Hide Add To Cart button for non registered users
Post by: discjockeyr on January 20, 2017, 08:53:53 AM
thanks guys i will check your suggestions
Title: Re: Hide Add To Cart button for non registered users
Post by: 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
Title: Re: Hide Add To Cart button for non registered users
Post by: Milbo on January 20, 2017, 22:08:44 PM
and now we just need someone who add it here https://docs.virtuemart.net/tutorials/templating-layouts.html
Title: Re: Hide Add To Cart button for non registered users
Post by: Rozie on January 26, 2018, 13:35:14 PM
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
Title: Re: Hide Add To Cart button for non registered users
Post by: Studio 42 on January 26, 2018, 13:51:45 PM
Sorry a typo:
<?php 
if(empty(JFactory::getUser()->id)) {
// echo "please login";
return;
?>
Title: Re: Hide Add To Cart button for non registered users
Post by: Rozie on January 26, 2018, 14:56:35 PM
That works perfect, thank you so much for your help it is greatly appreciated.