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

#   How to calculate and save the information in custom fields

##

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

Less More

- Posts: 285
- Thank you received: 42
-
-

2 years 8 months ago [\#359789](#359789) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  *[How to calculate and save the information in custom fields](/forum/35-orders-management/907904-how-to-calculate-and-save-the-information-in-custom-fields#359789 "-- HikaShop version -- : 5.0.3 -- Joomla version -- : 4.4.2 -- PHP version -- : 8.1.27 -- Browser(s) name and version -- : Google chrome  Hi, I want to add 2 new custom fields witch are visibles in back-end (order), and fromnt end (affiliate). The main question is how can I get the value from &quot;Subtotal&quot; and &quot;Coupon&quot; and to do basic math like &quot;subtotal - coupon&quot; and to save the result in a custom field. I need so save the value in a custom field because I want to show this value (sum of more custom fields) in Front-end -&gt; Affiliate account, like the value that the affiliate will recive. I need to do it like this because it's a custom way to do the math for what I need.")* was created by *[oxido](/forum/user/29793-oxido "View oxido's Profile")*

-- HikaShop version -- : 5.0.3
-- Joomla version -- : 4.4.2
-- PHP version -- : 8.1.27
-- Browser(s) name and version -- : Google chrome

Hi,
I want to add 2 new custom fields witch are visibles in back-end (order), and fromnt end (affiliate).
The main question is how can I get the value from "Subtotal" and "Coupon" and to do basic math like "subtotal - coupon" and to save the result in a custom field.
I need so save the value in a custom field because I want to show this value (sum of more custom fields) in Front-end -&gt; Affiliate account, like the value that the affiliate will recive.
I need to do it like this because it's a custom way to do the math for what I need.

- [ ![hika-custom-field-calc-oxido.jpg](/forum/attachment/58988) ](/forum/attachment/58988 "...calc-oxido.jpg") [ ](/forum/attachment/58988?download=1 "...calc-oxido.jpg")
- [ ![hika-custom-field-calc-2-oxido.jpg](/forum/attachment/58989) ](/forum/attachment/58989 "...lc-2-oxido.jpg") [ ](/forum/attachment/58989?download=1 "...lc-2-oxido.jpg")

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

2 years 8 months ago [\#359791](#359791) 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 calculate and save the information in custom fields](/forum/35-orders-management/907904-how-to-calculate-and-save-the-information-in-custom-fields#359791 "-- HikaShop version -- : 5.0.3 -- Joomla version -- : 4.4.2 -- PHP version -- : 8.1.27 -- Browser(s) name and version -- : Google chrome  Hi, I want to add 2 new custom fields witch are visibles in back-end (order), and fromnt end (affiliate). The main question is how can I get the value from &quot;Subtotal&quot; and &quot;Coupon&quot; and to do basic math like &quot;subtotal - coupon&quot; and to save the result in a custom field. I need so save the value in a custom field because I want to show this value (sum of more custom fields) in Front-end -&gt; Affiliate account, like the value that the affiliate will recive. I need to do it like this because it's a custom way to do the math for what I need.")*

Hi,

You need to develop a HikaShop plugin and implement in it the event onBeforeOrderCreate and onBeforeOrderUpdate:
[ www.hikashop.com/support/documentation/6...#onBeforeOrderCreate](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#onBeforeOrderCreate)
In them, you want to have your PHP code to:
- potentially load the data of the order from the database if not already available in $order ( [ www.hikashop.com/support/documentation/6...umentation.html#code](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#code) )
- substract the subtotal and coupon values. You'll want to do a var_dump() of the data to check that you have what you need for your calculations and how to access it. For example, when the order is being created, you'll have the value of the coupon in $order-&gt;order_discount_price and the whole data of the coupon in $order-&gt;cart-&gt;coupon, and you'll have the subtotal object in $order-&gt;cart-&gt;total ( $order-&gt;cart-&gt;total-&gt;price_value_with_tax or $order-&gt;cart-&gt;total-&gt;price_value based on whether you want the subtotal with or without taxes )
- set the result of your calculation in $order-&gt;xxx where xxx is the column name of your custom field. The save of the order afterwards will automatically save the value to the database for you.

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

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

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