Author Topic: Remove add to cart button on specific shopper group?  (Read 1605 times)

discjockeyr

  • Beginner
  • *
  • Posts: 36
Remove add to cart button on specific shopper group?
« 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

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10878
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: Remove add to cart button on specific shopper group?
« Reply #1 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) {

}
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4722
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Remove add to cart button on specific shopper group?
« Reply #2 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;

discjockeyr

  • Beginner
  • *
  • Posts: 36
Re: Remove add to cart button on specific shopper group?
« Reply #3 on: October 07, 2019, 12:19:45 PM »
thanks guys,
i would check your suggestions