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

#   Use product custom field in price calculation

##

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

Less More

- Posts: 10
- Thank you received: 0
-
-

14 years 4 months ago [\#55303](#55303) by [Verneda](/forum/user/7975-verneda "View Verneda's Profile")  *[Use product custom field in price calculation](/forum/4-how-to/55303-use-product-custom-field-in-price-calculation#55303 "I'm trying to modify the price of a product based on a custom field.  I have a custom field named &quot;marcaje&quot;, whose value is a character (&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, etc)  In the function hikashop&#95;product&#95;price&#95;for&#95;quantity&#95;in&#95;cart i try to refer to that value and modify the price based on that:  It can be done? How?  Thank you!")* was created by *[Verneda](/forum/user/7975-verneda "View Verneda's Profile")*

I'm trying to modify the price of a product based on a custom field.

I have a custom field named "marcaje", whose value is a character ("A", "B", "C", etc)

In the function hikashop_product_price_for_quantity_in_cart i try to refer to that value and modify the price based on that:
Code:

if(($product-&gt;marcaje)=="A"){ }

It can be done? How?

Thank you!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzU1MzAzLXVzZS1wcm9kdWN0LWN1c3RvbS1maWVsZC1pbi1wcmljZS1jYWxjdWxhdGlvbj90bXBsPW1hcmtkb3du) 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")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

14 years 4 months ago [\#55371](#55371) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Use product custom field in price calculation](/forum/4-how-to/55303-use-product-custom-field-in-price-calculation#55371 "I'm trying to modify the price of a product based on a custom field.  I have a custom field named &quot;marcaje&quot;, whose value is a character (&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, etc)  In the function hikashop&#95;product&#95;price&#95;for&#95;quantity&#95;in&#95;cart i try to refer to that value and modify the price based on that:  It can be done? How?  Thank you!")*

Sure it can be done like that.

What kind of custom field are you using ?
A custom product field or a custom item field ?

You should look at the custom price plugin:
plugins/system/custom_price/custom_price.php

You will have an example of what to do.

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

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

Less More

- Posts: 10
- Thank you received: 0
-
-

14 years 4 months ago [\#55409](#55409) by [Verneda](/forum/user/7975-verneda "View Verneda's Profile")  Replied by *[Verneda](/forum/user/7975-verneda "View Verneda's Profile")* on topic *[Re: Use product custom field in price calculation](/forum/4-how-to/55303-use-product-custom-field-in-price-calculation#55409 "I'm trying to modify the price of a product based on a custom field.  I have a custom field named &quot;marcaje&quot;, whose value is a character (&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, etc)  In the function hikashop&#95;product&#95;price&#95;for&#95;quantity&#95;in&#95;cart i try to refer to that value and modify the price based on that:  It can be done? How?  Thank you!")*

I have a field of item kind (tecnica) and can access it with the "arrow" operator Code:

if(!empty($product-&gt;tecnica)){...}

but with product kind don't know how to.

I have added a product custom field named "test" of type text to a product, and modified *hikashop\_product\_price\_for\_quantity\_in\_cart* in custom_price.php
Code:

function hikashop_product_price_for_quantity_in_cart(&amp;$product){ $currencyClass = hikashop_get('class.currency'); $quantity = @$product-&gt;cart_product_quantity; if(empty($product-&gt;prices)){ $price= null; $price-&gt;price_currency_id = hikashop_getCurrency(); $price-&gt;price_min_quantity = 1; $product-&gt;prices = array($price); } if(!empty($product-&gt;test)) { foreach($product-&gt;prices as $k =&gt; $price){ $product-&gt;prices[$k]-&gt;price_value == 100; $product-&gt;prices[$k]-&gt;price_value_with_tax == 118; } } $currencyClass-&gt;quantityPrices($product-&gt;prices,$quantity,$product-&gt;cart_product_total_quantity);

but it's not working.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzU1MzAzLXVzZS1wcm9kdWN0LWN1c3RvbS1maWVsZC1pbi1wcmljZS1jYWxjdWxhdGlvbj90bXBsPW1hcmtkb3du) 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")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

14 years 4 months ago [\#55412](#55412) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Use product custom field in price calculation](/forum/4-how-to/55303-use-product-custom-field-in-price-calculation#55412 "I'm trying to modify the price of a product based on a custom field.  I have a custom field named &quot;marcaje&quot;, whose value is a character (&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, etc)  In the function hikashop&#95;product&#95;price&#95;for&#95;quantity&#95;in&#95;cart i try to refer to that value and modify the price based on that:  It can be done? How?  Thank you!")*

You first need to load the product data:

$productClass = hikashop_get('class.product');
$productData = $productClass-&gt;get($product-&gt;product_id);
if(!empty($productData-&gt;test)) {

....etc...

The following user(s) said Thank You: [Verneda](/forum/user/7975-verneda "View Verneda's Profile")

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

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

Less More

- Posts: 10
- Thank you received: 0
-
-

14 years 4 months ago [\#55428](#55428) by [Verneda](/forum/user/7975-verneda "View Verneda's Profile")  Replied by *[Verneda](/forum/user/7975-verneda "View Verneda's Profile")* on topic *[Re: Use product custom field in price calculation](/forum/4-how-to/55303-use-product-custom-field-in-price-calculation#55428 "I'm trying to modify the price of a product based on a custom field.  I have a custom field named &quot;marcaje&quot;, whose value is a character (&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, etc)  In the function hikashop&#95;product&#95;price&#95;for&#95;quantity&#95;in&#95;cart i try to refer to that value and modify the price based on that:  It can be done? How?  Thank you!")*

Worked like a charm, thank you!

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

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

[](#top)
