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

#   How to combine product variants with custom field

##

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

Less More

- Posts: 58
- Thank you received: 2
-
-

9 years 1 month ago [\#279415](#279415) by [woidl](/forum/user/39777-woidl "View woidl's Profile")  *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#279415 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")* was created by *[woidl](/forum/user/39777-woidl "View woidl's Profile")*

-- HikaShop version -- : 3.2.0
-- Joomla version -- : 3.8
-- PHP version -- : 7

Hi,

I made a custom field (text area) to be shown beside the product.
The customer is now able to fill in his personal text for a greeting-card message.
This greeting card costs an additional amount of 5 Euro.

Problem:
The text area is always there and customers can always fill in a text - even if the choose "NO, thank you" to the greeting card.

Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)?
Maybe just visible when the choice is YES? Or just editable when chosen YES?

Screenshots:
one product with variants plus custom field
one product plus second product (greeting card) options

- [ ![product-variants-plus-textarea.jpg](/forum/attachment/40561) ](/forum/attachment/40561 "...s-textarea.jpg") [ ](/forum/attachment/40561?download=1 "...s-textarea.jpg")
- [ ![product-options-plus-textarea.jpg](/forum/attachment/40562) ](/forum/attachment/40562 "...s-textarea.jpg") [ ](/forum/attachment/40562?download=1 "...s-textarea.jpg")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL3Byb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84OTIxNTYtaG93LXRvLWNvbWJpbmUtcHJvZHVjdC12YXJpYW50cy13aXRoLWN1c3RvbS1maWVsZD90bXBsPW1hcmtkb3du) 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: 86320
- Thank you received: 14276
-
-

9 years 1 month ago [\#279441](#279441) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#279441 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")*

Hi,

There is no option for that.
That would require adding some custom javascript on the product page in order to hide/display the field based on the characteristic selection.

An alternative is to duplicate the product, one for the card without message, and one for the card with the message.

Or, you could also do it like that, without any coding:
Don't use a characteristic. Have instead a custom item field with its column name being "amount" configured as a simple dropdown with two values, and in each value set the title to what you want to display as choice on the dropdown and as value the amount you want to charge. Then, in your text custom field, use the "display limited to" setting to only display it for one of the two values of your new custom item field.
Finally, configure the donation plugin of HikaShop: [ demo.hikashop.com/index.php/en/hikashop/...t-page/donation-page](https://demo.hikashop.com/index.php/en/hikashop/product-page/donation-page)
That way, it will take the value selected in the dropdown by the customer as price for the product once in the cart.

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

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

Less More

- Posts: 58
- Thank you received: 2
-
-

9 years 1 month ago [\#279529](#279529) by [woidl](/forum/user/39777-woidl "View woidl's Profile")  Replied by *[woidl](/forum/user/39777-woidl "View woidl's Profile")* on topic *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#279529 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")*

Hi,

thanks for this very clever solution.

Unfortunately I am already using the custom field with the table name "amount" for another purpose (fill in the amount for gift vouchers).
So I cannot save another custom field with "amount".

Duplicating products is the only solution without coding?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL3Byb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84OTIxNTYtaG93LXRvLWNvbWJpbmUtcHJvZHVjdC12YXJpYW50cy13aXRoLWN1c3RvbS1maWVsZD90bXBsPW1hcmtkb3du) 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: 86320
- Thank you received: 14276
-
-

9 years 4 weeks ago [\#279548](#279548) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#279548 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")*

Hi,

You could create another custom field, and make a copy of the donation plugin, changing its name and the field name in it so that you could have both running in parallel. However, without any coding knowledge, it will be difficult. But it will be easy for anyone knowing even a bit of coding. So you could ask our partners: [ www.hikashop.com/home/our-partners.html](https://www.hikashop.com/home/our-partners.html)
They should be able to do that for you for a small price.

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

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

Less More

- Posts: 64
- Thank you received: 7
-
-

8 years 10 months ago [\#284995](#284995) by [justme](/forum/user/40056-justme "View justme's Profile")  Replied by *[justme](/forum/user/40056-justme "View justme's Profile")* on topic *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#284995 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")*

> nicolas wrote: Hi,
> Or, you could also do it like that, without any coding:
> Don't use a characteristic. Have instead a custom item field with its column name being "amount" configured as a simple dropdown with two values, and in each value set the title to what you want to display as choice on the dropdown and as value the amount you want to charge. Then, in your text custom field, use the "display limited to" setting to only display it for one of the two values of your new custom item field.
> Finally, configure the donation plugin of HikaShop: [ demo.hikashop.com/index.php/en/hikashop/...t-page/donation-page](https://demo.hikashop.com/index.php/en/hikashop/product-page/donation-page)
> That way, it will take the value selected in the dropdown by the customer as price for the product once in the cart.

Hi Nicolas,

I have done what you suggest here and this is exactly the sollution to our problem. The only last problem is that this plugin changes the total price and not adds the amount in the selected field (from the donation plugin). Is it possible to alter the code so it adds the selected amount to the amount in the cart and not change the total amount? I guess I have to change this code:
Code:

$currencyClass-&gt;quantityPrices($product-&gt;prices,$quantity,$product-&gt;cart_product_total_quantity);

But I don't know how.

Thank you in advance,

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL3Byb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84OTIxNTYtaG93LXRvLWNvbWJpbmUtcHJvZHVjdC12YXJpYW50cy13aXRoLWN1c3RvbS1maWVsZD90bXBsPW1hcmtkb3du) 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: 86320
- Thank you received: 14276
-
-

8 years 10 months ago [\#284999](#284999) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#284999 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")*

Hi,

No, this plugin doesn't replace the total.
What this plugin does is that it uses the value entered in the custom field of that product as the unit price of that product.
If you increase the quantity of that product, or if you add other products, the total will take these into account.
If you mean that you want that the value entered in the custom field of that product is added to the unit price of that product the you need to change all the place where you have the code: Code:

hikashop_toFloat($product-&gt;$column)

to: Code:

hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value)

or Code:

hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value_with_tax)

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

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

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

Less More

- Posts: 64
- Thank you received: 7
-
-

8 years 9 months ago [\#285523](#285523) by [justme](/forum/user/40056-justme "View justme's Profile")  Replied by *[justme](/forum/user/40056-justme "View justme's Profile")* on topic *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#285523 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")*

Hi Nicolas,

A late response because I have been very sick. But I finally feel well enough to look at this again.
Thank you so much for this! You are great! This is exactly what I need.

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

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

Less More

- Posts: 64
- Thank you received: 7
-
-

8 years 9 months ago [\#285524](#285524) by [justme](/forum/user/40056-justme "View justme's Profile")  Replied by *[justme](/forum/user/40056-justme "View justme's Profile")* on topic *[How to combine product variants with custom field](/forum/26-product-category-display/892156-how-to-combine-product-variants-with-custom-field#285524 "-- HikaShop version -- : 3.2.0 -- Joomla version -- : 3.8 -- PHP version -- : 7  Hi,  I made a custom field (text area) to be shown beside the product. The customer is now able to fill in his personal text for a greeting-card message. This greeting card costs an additional amount of 5 Euro.  Problem: The text area is always there and customers can always fill in a text - even if the choose &quot;NO, thank you&quot; to the greeting card.  Is it possible to make the the custom field depending to the choice of the user ( greeting card yes or no)? Maybe just visible when the choice is YES? Or just editable when chosen YES?  Screenshots: one product with variants plus custom field one product plus second product (greeting card) options")*

For everyone else looking for adding a custom item field with a price to go on top of the price of the product. Do as Nicolas explained and change the donation plugin located in plugins/system/custom_price. Below is the code for custom_price.php
Code:

&lt;?php /** * @package HikaShop for Joomla! * @version 2.6.4 * @author hikashop.com * @copyright (C) 2010-2016 HIKARI SOFTWARE. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); ?&gt;&lt;?php jimport('joomla.plugin.plugin'); class plgSystemCustom_price extends JPlugin{ } if(!function_exists('hikashop_product_price_for_quantity_in_cart') &amp;&amp; !function_exists('hikashop_product_price_for_quantity_in_order')) { function hikashop_product_price_for_quantity_in_cart(&amp;$product){ $currencyClass = hikashop_get('class.currency'); $quantity = @$product-&gt;cart_product_quantity; $plugin = JPluginHelper::getPlugin('system', 'custom_price'); if(version_compare(JVERSION,'2.5','&lt;')){ jimport('joomla.html.parameter'); $params = new JParameter($plugin-&gt;params); } else { $params = new JRegistry($plugin-&gt;params); } $taxes = $params-&gt;get('taxes',0); $column = $params-&gt;get('field','amount'); if(!empty($product-&gt;$column)){ if(empty($product-&gt;prices)){ $price= new stdClass(); $price-&gt;price_currency_id = hikashop_getCurrency(); $price-&gt;price_min_quantity = 1; $product-&gt;prices = array($price); } foreach($product-&gt;prices as $k =&gt; $price){ if($taxes &amp;&amp; $product-&gt;product_type=='variant' &amp;&amp; empty($product-&gt;product_tax_id)){ $productClass = hikashop_get('class.product'); $main = $productClass-&gt;get($product-&gt;product_parent_id); $product-&gt;product_tax_id = $main-&gt;product_tax_id; } switch($taxes){ case 2: $product-&gt;prices[$k]-&gt;price_value = $currencyClass-&gt;getUntaxedPrice(hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value_with_tax),hikashop_getZone(),$product-&gt;product_tax_id); $product-&gt;prices[$k]-&gt;taxes=$currencyClass-&gt;taxRates; $product-&gt;prices[$k]-&gt;price_value_with_tax = hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value_with_tax); break; case 1: $product-&gt;prices[$k]-&gt;price_value = hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value_with_tax); $product-&gt;prices[$k]-&gt;price_value_with_tax = $currencyClass-&gt;getTaxedPrice(hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value_with_tax),hikashop_getZone(),$product-&gt;product_tax_id); $product-&gt;prices[$k]-&gt;taxes=$currencyClass-&gt;taxRates; break; case 0: default: $product-&gt;prices[$k]-&gt;price_value = hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value_with_tax); $product-&gt;prices[$k]-&gt;price_value_with_tax = hikashop_toFloat($product-&gt;$column+$product-&gt;prices[$k]-&gt;price_value_with_tax); break; } } } $currencyClass-&gt;quantityPrices($product-&gt;prices,$quantity,$product-&gt;cart_product_total_quantity); } }

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

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

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

[](#top)
