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

#   Custom fields not changing depending on variant

##

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

Less More

- Posts: 366
- Thank you received: 26
-
-

4 years 10 months ago [\#337693](#337693) by [Thrane](/forum/user/31786-thrane "View Thrane's Profile")  *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337693 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")* was created by *[Thrane](/forum/user/31786-thrane "View Thrane's Profile")*

-- HikaShop version -- : 4.4.4
-- Joomla version -- : 3.10.3
-- PHP version -- : 7.4

Hi

I have added a custom field to a product and then added a charateristic.
The on the product added 2 variants with different entries in the custom field.

But on the page: [ passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv](https://passtheport.thr.nu/shop/ruby-port/lbv-late-bottled-vintage/quinta-das-lamelas-lbv) the field isn't changing when I chose a different variant?

"FLASKEÅR" should change ...
What to do here?

Regards
Thomas

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL3Byb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDM2MTUtY3VzdG9tLWZpZWxkcy1ub3QtY2hhbmdpbmctZGVwZW5kaW5nLW9uLXZhcmlhbnQ/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86289
- Thank you received: 14265
-
-

4 years 10 months ago [\#337707](#337707) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337707 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Hi,

The "FLASKEÅR" there is in the description of the product.
So you would have to edit the variant and change the text of the description to have that change taken into effect when you use the characteristic dropdown.

I suppose you didn't configure the custom product field to appear on the product page and thus it's just not being displayed.

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

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

Less More

- Posts: 366
- Thank you received: 26
-
-

4 years 10 months ago [\#337751](#337751) by [Thrane](/forum/user/31786-thrane "View Thrane's Profile")  Replied by *[Thrane](/forum/user/31786-thrane "View Thrane's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337751 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Hi

"FLASKEÅR" is not in the description, but has been coded in product/show_default.php like this:

&lt;?php
if(isset($this-&gt;row-&gt;bottleyear) &amp;&amp; !empty($this-&gt;row-&gt;bottleyear)){ ?&gt;
&lt;div class="hikashop_product_bottleyear"&gt;
&lt;div&gt;&lt;h4&gt;Flaskeår&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;&lt;?php echo $this-&gt;row-&gt;bottleyear; ?&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;?php }
?&gt;

And each variant has different value in FLASKEÅR.

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

- **[Philip](/forum/user/34318-philip "View Philip's Profile")**
- [![Philip's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar34318_2015-11-18-2.png)](/forum/user/34318-philip "View Philip's Profile")
- [ Offline](/forum/user/34318-philip)

Less More

- Posts: 4820
- Thank you received: 654
-
-

4 years 10 months ago -  4 years 10 months ago [\#337766](#337766) by [Philip](/forum/user/34318-philip "View Philip's Profile")  Replied by *[Philip](/forum/user/34318-philip "View Philip's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337766 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Hello,

Select Characteristics will update **parts of the page** but not all, from this all we can tell you is that your custom code isn't in the good place.
**BUT** if each product variant can have different "*Flaskear*" why don't you use as suggested by Nicolas to use Description as if each variant description is different this part will be update by selecting characteristics.
Create dynamic data from variant to another is of course possible but not that easy, especially compare to Nicolas idea.

but, if for a reason or another **you need** to use this custom code, then you have to "associated" your code WITH a part that will be updated for each variant as description (or another part).

For description example, you will find this code part in the view **product**/**show**, look for this code "**hikashop\_product\_description\_&lt;?php echo $variant\_name; ?&gt;**" to find dynamic description code.

Hope this will help you to get what you need.
Regards

Last edit: 4 years 10 months ago by [Philip](/forum/user/34318-philip "View Philip's Profile").

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

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

Less More

- Posts: 366
- Thank you received: 26
-
-

4 years 10 months ago [\#337844](#337844) by [Thrane](/forum/user/31786-thrane "View Thrane's Profile")  Replied by *[Thrane](/forum/user/31786-thrane "View Thrane's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337844 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Thanks Philip!

These custom fields are made to make it easier for my customer who owns the shop.
I'm pretty sure he will f**k things up, if he had to make this in the description ![:-)](/media/kunena/emoticons/9.png ":-)")

I will look into your suggestion, thank you!!

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

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

Less More

- Posts: 366
- Thank you received: 26
-
-

4 years 10 months ago [\#337851](#337851) by [Thrane](/forum/user/31786-thrane "View Thrane's Profile")  Replied by *[Thrane](/forum/user/31786-thrane "View Thrane's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337851 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

So I have managed to get some of it to work, but I can't quite figure out how to change between the data.
I have set display to block, just to check if I got the data, but when I set it to display:none; I don't see anything, not even when changing variant.

Any advice?

This is the code I use: Code:

- TEST START - &lt;?php foreach($this-&gt;element-&gt;variants as $variant) { $this-&gt;row =&amp; $variant; $variant_name = array (); if(!empty($variant-&gt;characteristics)) { foreach($variant-&gt;characteristics as $k =&gt; $ch) { $variant_name[] = $ch-&gt;characteristic_id; } } $variant_name = implode('_', $variant_name); $this-&gt;variant_name = '_' . $variant_name; if(!empty($variant-&gt;bottleyear)) { ?&gt; &lt;div id="hikashop_product_description_&lt;?php echo $variant_name; ?&gt;" style="display:block;"&gt;&lt;?php echo JHTML::_('content.prepare',preg_replace('#&lt;hr *id="system-readmore" */&gt;#i','',$variant-&gt;product_description)); ?&gt;Bottle year: &lt;?php echo $variant-&gt;bottleyear; ?&gt;&lt;/div&gt; &lt;?php } } ?&gt; - TEST END -

And the page can be seen here:
[ passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv](https://passtheport.thr.nu/shop/ruby-port/lbv-late-bottled-vintage/quinta-das-lamelas-lbv)

Regards
Thomas

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL3Byb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDM2MTUtY3VzdG9tLWZpZWxkcy1ub3QtY2hhbmdpbmctZGVwZW5kaW5nLW9uLXZhcmlhbnQ/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86289
- Thank you received: 14265
-
-

4 years 10 months ago [\#337859](#337859) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337859 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Hi,

You're almost there.
You have 3 things left though:
- You need to change hikashop_product_description to something else as that is already used by the description of the product.
You could use for example hikashop_product_bottleyear instead.
- As you can see all the divs where the data displayed refreshes based on the selected variants ahve an id like this: hikashop_product_description_main in show_default.
So you need to change hikashop_product_bottleyear to hikashop_product_bottleyear_main in the id of your main div so that the characteristic system will be able to find it and match it with the variants ones.
- In the show_block_characteristics view file, you can find this line: Code:

var names = ['id','name','code','image','price','quantity','description','weight','url','width','length','height','contact','custom_info','files'];

It tells the system what names to search in the HTML. So in there, you should also add bottleyear

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

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

Less More

- Posts: 366
- Thank you received: 26
-
-

4 years 10 months ago [\#337865](#337865) by [Thrane](/forum/user/31786-thrane "View Thrane's Profile")  Replied by *[Thrane](/forum/user/31786-thrane "View Thrane's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337865 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Hi nicolas
Great! Almost there, but I must miss something.
The BOTTLEYEAR is not there from the beginning, but shows when I change variant to 2016.
But changing back to 2015, it stays the bottleyear from 2016 - 2015 has to be 2019.

Can you spot my mistake somewhere?
Code:

var names = ['id','name','code','image','price','quantity','description','weight','url','width','length','height','contact','custom_info','files','bottleyear'];

Code:

- TEST START - &lt;div id="hikashop_product_bottleyear_main" class="hikashop_product_bottleyear_main" itemprop="bottleyear"&gt; &lt;?php foreach($this-&gt;element-&gt;variants as $variant) { $this-&gt;row =&amp; $variant; $variant_name = array (); if(!empty($variant-&gt;characteristics)) { foreach($variant-&gt;characteristics as $k =&gt; $ch) { $variant_name[] = $ch-&gt;characteristic_id; } } $variant_name = implode('_', $variant_name); $this-&gt;variant_name = '_' . $variant_name; if(!empty($variant-&gt;bottleyear)) { ?&gt; &lt;div id="hikashop_product_bottleyear_&lt;?php echo $variant_name; ?&gt;" style="display:none;"&gt;Bottle year: &lt;?php echo $variant-&gt;bottleyear; ?&gt;&lt;/div&gt; &lt;?php } } ?&gt; &lt;/div&gt; - TEST END -

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL3Byb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDM2MTUtY3VzdG9tLWZpZWxkcy1ub3QtY2hhbmdpbmctZGVwZW5kaW5nLW9uLXZhcmlhbnQ/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86289
- Thank you received: 14265
-
-

4 years 10 months ago [\#337867](#337867) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337867 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Hi,

The issue is that the variant divs shouldn't be inside the hikashop_product_bottleyear_main div.
The main div needs to be elsewhere and in it, you want to display the default value to display before the user selects something.

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

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

Less More

- Posts: 366
- Thank you received: 26
-
-

4 years 10 months ago [\#337878](#337878) by [Thrane](/forum/user/31786-thrane "View Thrane's Profile")  Replied by *[Thrane](/forum/user/31786-thrane "View Thrane's Profile")* on topic *[Custom fields not changing depending on variant](/forum/26-product-category-display/903615-custom-fields-not-changing-depending-on-variant#337878 "-- HikaShop version -- : 4.4.4 -- Joomla version -- : 3.10.3 -- PHP version -- : 7.4  Hi  I have added a custom field to a product and then added a charateristic. The on the product added 2 variants with different entries in the custom field.  But on the page:   passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv  the field isn't changing when I chose a different variant?  &quot;FLASKEÅR&quot; should change ... What to do here?  Regards Thomas")*

Hi

Oh I get it now, perfect!

And thank you so much - I'm always amazed by the knowledge you guys have and your dedication on helping out - even when I "demand" weird stuff!

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

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

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

[](#top)
