Changing the user group after the 3rd purchase

  • Posts: 193
  • Thank you received: 15
  • Hikashop Business
11 months 2 weeks ago #357378

Hi,
Is it possible to configure it so that after placing the third order, the customer will be automatically transferred to another Joomla user group? So as to assign it to a group with a specific discount.
Tom

Please Log in or Create an account to join the conversation.

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
11 months 2 weeks ago #357382

Hi,

There is no option to do it.
However, you should be able to do it with a bit of coding and a mass action.
For example, you can create a mass action "order" with a trigger "after an order is updated" and with an action "run PHP code" with such code:

$db = JFactory::getDBO();
$db->setQuery('SELECT count(order_id) FROM #__hikashop_order WHERE order_user_id={order_user_id} AND order_status IN ("confirmed", "shipped")');
$number_of_orders = $db->loadResult();
if($number_of_orders >= 3) {
 $userClass = hikashop_get('class.user');
 $hkUser = $userClass->get({order_user_id});
 if(!empty($hkUser->user_cms_id)) {
  $user = clone(JFactory::getUser($hkUser->user_cms_id));
  jimport('joomla.access.access');
  $userGroups = JAccess::getGroupsByUser($hkUser->user_cms_id, true);
  $userGroups[] = XXX;
  $user->set('groups',$userGroups);
  $user->save();
 }
}
where XXX is the id of the user group you want to add to the user account.

Please Log in or Create an account to join the conversation.

  • Posts: 193
  • Thank you received: 15
  • Hikashop Business
11 months 2 weeks ago #357399

Thank you, I will test :)
Tom

Please Log in or Create an account to join the conversation.

Time to create page: 0.040 seconds
Powered by Kunena Forum