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

#   set Value of custom field by plugin

##

- **[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")**
- [![aminweb's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38602.png)](/forum/user/38602-aminweb "View aminweb's Profile") Topic Author
- [ Offline](/forum/user/38602-aminweb)
- Amin

Less More

- Posts: 138
- Thank you received: 4
-
-
-

1 year 11 months ago [\#364475](#364475) by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")  *[set Value of custom field by plugin](/forum/26-product-category-display/908872-set-value-of-custom-field-by-plugin#364475 "hello, I have a custom field (dropdown) on User cloumn. I want set default value and readonly it by plugin. my plugin codes:  But i not working as well. can you help me? thank you")* was created by *[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")*

hello,
I have a custom field (dropdown) on User cloumn.
I want set default value and readonly it by plugin.
my plugin codes:
Code:

&lt;?php defined('_JEXEC') or die; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Factory; class PlgSystemHikaShopCustomize extends CMSPlugin { public function onHikashopBeforeDisplayView(&amp;$view) { // Only modify the user registration form view if ($view-&gt;getName() !== 'user' &#124;&#124; $view-&gt;getLayout() !== 'form') { return; } $user = Factory::getUser(); // Check if the logged-in user is in the 'Teacher' group (group ID 15) if (in_array(15, $user-&gt;getAuthorisedGroups())) { // Ensure Hikashop helper is loaded if (!class_exists('hikashopFieldClass')) { if (!include_once(JPATH_ADMINISTRATOR . '/components/com_hikashop/helpers/helper.php')) { return; } } $class = hikashop_get('class.field'); $field = $class-&gt;getField('teacher_name', 'user'); $lenew = new stdClass(); $lenew-&gt;value = "azur"; $lenew-&gt;disabled = 0; $field-&gt;field_value['bleue'] = $lenew; $class-&gt;addValue($field-&gt;field_id, 'bleue', 'azur', 0); } } }

But i not working as well. can you help me? thank you

---

Joomla Developer \| am.ebrahimzadeh\[at\]gmail.com

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDg4NzItc2V0LXZhbHVlLW9mLWN1c3RvbS1maWVsZC1ieS1wbHVnaW4/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: 86359
- Thank you received: 14294
-
-

1 year 11 months ago [\#364484](#364484) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[set Value of custom field by plugin](/forum/26-product-category-display/908872-set-value-of-custom-field-by-plugin#364484 "hello, I have a custom field (dropdown) on User cloumn. I want set default value and readonly it by plugin. my plugin codes:  But i not working as well. can you help me? thank you")*

Hi,

First, the code: Code:

// Ensure Hikashop helper is loaded if (!class_exists('hikashopFieldClass')) { if (!include_once(JPATH_ADMINISTRATOR . '/components/com_hikashop/helpers/helper.php')) { return; } }

should not do anything. The event onHikashopBeforeDisplayView is only called by the main helper file of HikaShop. So if your method is called, HikaShop is already loaded. Thus, you can remove it.

Second, in onHikashopBeforeDisplayView the field data is already loaded in the view and the view will use the data already loaded. So there is no need to load the field data, and you need instead to update the field data in the view.

So, you want to use something like this: Code:

$lenew = new stdClass(); $lenew-&gt;value = "azur"; $lenew-&gt;disabled = 0; $view-&gt;extraFields['user']['teacher_name']-&gt;field_value['bleue'] = $lenew;

The following user(s) said Thank You: [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")

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

- **[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")**
- [![aminweb's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38602.png)](/forum/user/38602-aminweb "View aminweb's Profile") Topic Author
- [ Offline](/forum/user/38602-aminweb)
- Amin

Less More

- Posts: 138
- Thank you received: 4
-
-
-

1 year 11 months ago [\#364490](#364490) by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")  Replied by *[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")* on topic *[set Value of custom field by plugin](/forum/26-product-category-display/908872-set-value-of-custom-field-by-plugin#364490 "hello, I have a custom field (dropdown) on User cloumn. I want set default value and readonly it by plugin. my plugin codes:  But i not working as well. can you help me? thank you")*

thank you,
I updated plugin codes by: Code:

&lt;?php defined('_JEXEC') or die; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Factory; class PlgSystemHikaShopCustomize extends CMSPlugin { public function onHikashopBeforeDisplayView(&amp;$view) { // Only modify the user registration form view if ($view-&gt;getName() !== 'user' &#124;&#124; $view-&gt;getLayout() !== 'form') { return; } $user = Factory::getUser(); // Check if the logged-in user is in the 'Teacher' group (group ID 15) if (in_array(15, $user-&gt;getAuthorisedGroups())) { $class = hikashop_get('class.field'); $field = $class-&gt;getField('teacher_name', 'user'); $lenew = new stdClass(); $lenew-&gt;value = $user-&gt;id; $lenew-&gt;disabled = 0; $view-&gt;extraFields['user']['teacher_name']-&gt;field_value[$user-&gt;id] = $lenew; } } }

But not affect on field atall (not set value and disable)

---

Joomla Developer \| am.ebrahimzadeh\[at\]gmail.com

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDg4NzItc2V0LXZhbHVlLW9mLWN1c3RvbS1maWVsZC1ieS1wbHVnaW4/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: 86359
- Thank you received: 14294
-
-

1 year 11 months ago [\#364493](#364493) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[set Value of custom field by plugin](/forum/26-product-category-display/908872-set-value-of-custom-field-by-plugin#364493 "hello, I have a custom field (dropdown) on User cloumn. I want set default value and readonly it by plugin. my plugin codes:  But i not working as well. can you help me? thank you")*

Hi,

Well, you need to do some debugging.
Do a var_dump of $view-&gt;extraFields and check that the code goes past your user group check. That should be a good start.

The following user(s) said Thank You: [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")

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

- **[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")**
- [![aminweb's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38602.png)](/forum/user/38602-aminweb "View aminweb's Profile") Topic Author
- [ Offline](/forum/user/38602-aminweb)
- Amin

Less More

- Posts: 138
- Thank you received: 4
-
-
-

1 year 11 months ago [\#364497](#364497) by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")  Replied by *[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")* on topic *[set Value of custom field by plugin](/forum/26-product-category-display/908872-set-value-of-custom-field-by-plugin#364497 "hello, I have a custom field (dropdown) on User cloumn. I want set default value and readonly it by plugin. my plugin codes:  But i not working as well. can you help me? thank you")*

I done by this codes:
Code:

&lt;?php defined('_JEXEC') or die; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Factory; class PlgSystemHikaShopCustomize extends CMSPlugin { public function onHikashopBeforeDisplayView(&amp;$view) { // Only modify the user registration form view if ($view-&gt;getName() !== 'user' &#124;&#124; $view-&gt;getLayout() !== 'form') { return; } $user = Factory::getUser(); // Check if the logged-in user is in the 'Teacher' group (group ID 15) if (in_array(15, $user-&gt;getAuthorisedGroups())) { // Ensure Hikashop helper is loaded if (!class_exists('hikashopFieldClass')) { if (!include_once(JPATH_ADMINISTRATOR . '/components/com_hikashop/helpers/helper.php')) { return; } } $fieldClass = hikashop_get('class.field'); $field = $fieldClass-&gt;getField('teacher_name', 'user'); // Set the field default value to the current user's ID $field-&gt;field_default = $user-&gt;id; // Generate the field HTML with the correct number of arguments $field-&gt;field_html = $fieldClass-&gt;display($field, $user-&gt;id, 'data[user][teacher_name]'); // Modify the field HTML to disable the field if (!empty($field-&gt;field_html)) { // Disable the select field $field-&gt;field_html = str_replace('&lt;select', '&lt;select disabled="disabled"', $field-&gt;field_html); } // Update the field in the view $view-&gt;fields['user']['teacher_name'] = $field; // Set the value in the form data if (isset($view-&gt;user)) { $view-&gt;user-&gt;teacher_name = $user-&gt;id; } else { $view-&gt;user = new stdClass(); $view-&gt;user-&gt;teacher_name = $user-&gt;id; } $document = Factory::getDocument(); $script = " document.addEventListener('DOMContentLoaded', function() { var field = document.querySelector('select[name=\"data[user][teacher_name]\"]'); if (field) { field.disabled = true; } }); "; $document-&gt;addScriptDeclaration($script); } } }

---

Joomla Developer \| am.ebrahimzadeh\[at\]gmail.com

The following user(s) said Thank You: [nicolas](/forum/user/63-nicolas "View nicolas's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDg4NzItc2V0LXZhbHVlLW9mLWN1c3RvbS1maWVsZC1ieS1wbHVnaW4/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.051 seconds

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