Author Topic: Hide Add To Cart button for non registered users  (Read 4751 times)

discjockeyr

  • Beginner
  • *
  • Posts: 36
Hide Add To Cart button for non registered users
« 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

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 27846
  • Always on vacation
    • Jenkin Hill Internet
Re: Hide Add To Cart button for non registered users
« Reply #1 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)
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

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

Currently using VM 3.8.4.10335 on Joomla 3.9.21 PHP 7.4.9

jjk

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3693
  • using Matomo instead of Google Analytics
Re: Hide Add To Cart button for non registered users
« Reply #2 on: January 19, 2017, 18:47:16 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)
Code: [Select]
<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:
Code: [Select]
<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

  • Beginner
  • *
  • Posts: 36
Re: Hide Add To Cart button for non registered users
« Reply #3 on: January 20, 2017, 08:53:53 am »
thanks guys i will check your suggestions

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4367
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Hide Add To Cart button for non registered users
« Reply #4 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
Code: [Select]
<?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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10070
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Hide Add To Cart button for non registered users
« Reply #5 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
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Rozie

  • Beginner
  • *
  • Posts: 7
    • Rozegarden Website Design
Re: Hide Add To Cart button for non registered users
« Reply #6 on: January 26, 2018, 13:35:14 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
Code: [Select]
<?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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4367
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Hide Add To Cart button for non registered users
« Reply #7 on: January 26, 2018, 13:51:45 pm »
Sorry a typo:
Code: [Select]
<?php 
if(empty(JFactory::getUser()->id)) {
// echo "please login";
return;
?>

Rozie

  • Beginner
  • *
  • Posts: 7
    • Rozegarden Website Design
Re: Hide Add To Cart button for non registered users
« Reply #8 on: January 26, 2018, 14:56:35 pm »
That works perfect, thank you so much for your help it is greatly appreciated.