VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: discjockeyr on October 03, 2019, 13:25:11 PM

Title: Remove add to cart button on specific shopper group?
Post by: discjockeyr on October 03, 2019, 13:25:11 PM
Hi there,
On my website until now i had a "wholesale" shopper group and i add the registered customers that i want to this group to see prices and place online orders. Now i want to add a new price group "Retail" that the price will be available for non registered visitors but if i do that in the page details there is an Add To Cart button. is there a way to hide this button for non registered users and keep the price?

Thanks
Title: Re: Remove add to cart button on specific shopper group?
Post by: GJC Web Design on October 03, 2019, 16:20:09 PM
detect the shopper group in the template and either don't display or hide with css

find the shopper group with

$userModel = VmModel::getModel('user');
$vmuser = $userModel->getCurrentUser();
$vmgroup = $vmuser->shopper_groups;
//is an array
if(in_array(x, $vmgroup) {

}
Title: Re: Remove add to cart button on specific shopper group?
Post by: Studio 42 on October 03, 2019, 23:07:36 PM
Or simply use Joomla user, to check for guest. See all info for a Joomla user https://docs.joomla.org/Accessing_the_current_user_object
sample code :
$user = JFactory::getUser();

if (!$user->guest) {
  //any code for logged user
}

You can do an override in your template from components/com_virtuemart/sublayouts/addtocart.php in templates/YOURTEMPLATE/html/com_virtuemart/sublayouts/addtocart.php
for eg. after defined('_JEXEC') or die('Restricted access');
if(JFactory::getUser()->guest) return;
Title: Re: Remove add to cart button on specific shopper group?
Post by: discjockeyr on October 07, 2019, 12:19:45 PM
thanks guys,
i would check your suggestions