[Skip to main content](#vessel-content)

#   Assigning User Group on order creation

##

- **[NTV](/forum/user/69623-ntv "View NTV's Profile")**
- [![NTV's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/69623-ntv "View NTV's Profile") Topic Author
- [ Offline](/forum/user/69623-ntv)

Less More

- Posts: 47
- Thank you received: 6
-

2 years 11 months ago [\#357553](#357553) by [NTV](/forum/user/69623-ntv "View NTV's Profile")  *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#357553 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")* was created by *[NTV](/forum/user/69623-ntv "View NTV's Profile")*

-- HikaShop version -- : 5.0.2
-- Joomla version -- : 4.4.1
-- PHP version -- : 8
-- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)

Hi,

I want to assign a user group when a customer orders a certain product.

This is possible by setting "User group after purchase" for the product in question.

However, the user group is only assigned once the order is set to confirmed.

I am aware of the possible implications, but still want to assign user groups immediately after the order is created.

How would I go about doing this?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86578
- Thank you received: 14321
-
-

2 years 11 months ago [\#357566](#357566) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#357566 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")*

Hi,

You would have to edit the file plugins/hikashop/group/group.php and change the line: Code:

if($order-&gt;order_status != $confirmed){

to: Code:

if($order-&gt;order_status != 'created'){

That way, the group would be added when the order is created.

The following user(s) said Thank You: [NTV](/forum/user/69623-ntv "View NTV's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[NTV](/forum/user/69623-ntv "View NTV's Profile")**
- [![NTV's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/69623-ntv "View NTV's Profile") Topic Author
- [ Offline](/forum/user/69623-ntv)

Less More

- Posts: 47
- Thank you received: 6
-

2 years 11 months ago [\#357572](#357572) by [NTV](/forum/user/69623-ntv "View NTV's Profile")  Replied by *[NTV](/forum/user/69623-ntv "View NTV's Profile")* on topic *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#357572 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")*

Hi,

works fine, thanks a lot!

But this change will get overridden with the next update to group.php - correct?
If so, is there a way to make an override like with Views?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86578
- Thank you received: 14321
-
-

2 years 11 months ago [\#357574](#357574) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#357574 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")*

Hi,

That's correct.
You can make an override. Basically, you need to rename the plugin. Change its folder / files / class to new names based on the Joomla documentation on how to make plugins so that you basically have your own custom user group after purchase plugin.
This requires some development knowledge.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[NTV](/forum/user/69623-ntv "View NTV's Profile")**
- [![NTV's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/69623-ntv "View NTV's Profile") Topic Author
- [ Offline](/forum/user/69623-ntv)

Less More

- Posts: 47
- Thank you received: 6
-

2 years 11 months ago -  2 years 11 months ago [\#357682](#357682) by [NTV](/forum/user/69623-ntv "View NTV's Profile")  Replied by *[NTV](/forum/user/69623-ntv "View NTV's Profile")* on topic *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#357682 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")*

Hi,

I think that could be in the realm of my capabilities. Would I need to rename or copy the original Hika Plugin?

If I rename it, would the original not be added again with the new update?

And if I copy it, how would I stop the original from running as well?

Last edit: 2 years 11 months ago by [NTV](/forum/user/69623-ntv "View NTV's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86578
- Thank you received: 14321
-
-

2 years 11 months ago [\#357690](#357690) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#357690 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")*

Hi,

You would need to copy the plugin. The original plugin will be updated / added back automatically after each update, so if you don't want to use it, you want to disable it in the Joomla plugins manager.

The following user(s) said Thank You: [NTV](/forum/user/69623-ntv "View NTV's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[NTV](/forum/user/69623-ntv "View NTV's Profile")**
- [![NTV's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/69623-ntv "View NTV's Profile") Topic Author
- [ Offline](/forum/user/69623-ntv)

Less More

- Posts: 47
- Thank you received: 6
-

1 year 6 months ago -  1 year 6 months ago [\#367110](#367110) by [NTV](/forum/user/69623-ntv "View NTV's Profile")  Replied by *[NTV](/forum/user/69623-ntv "View NTV's Profile")* on topic *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#367110 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")*

Hi,
digging this up again, because we tried to delegate the assigning of user groups to HikaSerial and discovered that HikaSerial is not an option for us (yet).

However, I had another idea:
Could I create an onAfterOrderCreate() function in a custom plugin, check if there are user groups associated with the product and then set it myself, leaving the original HikaShop code untouched?

Sound counter-intuitive, but for me it would be less overhead and also future proof (since we already have a custom plugin).

Something like this:
Code:

foreach ($order-&gt;cart-&gt;full_products as $product) { $group = $product-&gt;product_group_after_purchase; if ($group != '') { $user = $userClass-&gt;get($order-&gt;order_user_id); $email = $user-&gt;user_email; // Find Joomla user via email $db = JFactory::getDbo(); $query = $db-&gt;getQuery(true) -&gt;select($db-&gt;quoteName('id')) -&gt;from($db-&gt;quoteName('#__users')) -&gt;where($db-&gt;quoteName('email') . ' = ' . $db-&gt;quote($email)); $db-&gt;setQuery($query); if ($id = $db-&gt;loadResult()) $user = JFactory::getUser($id); else return; UserHelper::addUserToGroup($user-&gt;id, $group); } }

Tested it, seems to work.

Any problems this may cause that I'm not aware of?

Last edit: 1 year 6 months ago by [NTV](/forum/user/69623-ntv "View NTV's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86578
- Thank you received: 14321
-
-

1 year 6 months ago [\#367114](#367114) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Assigning User Group on order creation](/forum/33-customers/907455-assigning-user-group-on-order-creation#367114 "-- HikaShop version -- : 5.0.2 -- Joomla version -- : 4.4.1 -- PHP version -- : 8 -- Browser(s) name and version -- : Firefox 120.0.1 (64-bit)  Hi,  I want to assign a user group when a customer orders a certain product.  This is possible by setting &quot;User group after purchase&quot; for the product in question.  However, the user group is only assigned once the order is set to confirmed.  I am aware of the possible implications, but still want to assign user groups immediately after the order is created.  How would I go about doing this?")*

Hi,

Well, that's basically similar to what I was suggesting in my previous message when I told you you could make a copy of the group plugin of HikaShop.
Whether you make a copy of the plugin, or you just copy / paste the onAfterOrderCreate function from the code of the plugin to your custom plugin and just apply the modification I proposed in my first message, either of these are fine.

The following user(s) said Thank You: [NTV](/forum/user/69623-ntv "View NTV's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2N1c3RvbWVycy85MDc0NTUtYXNzaWduaW5nLXVzZXItZ3JvdXAtb24tb3JkZXItY3JlYXRpb24/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.056 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
