Skip Navigation

[Resolved] Fields calculation

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 7 replies, has 2 voices.

Last updated by Luo Yang 7 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#459475

Hello all,

Hello all,
I need the help/custom work/hint how to set post fields calculation. Egg. I have come custom fields group, and I need calculation of some fields from two fields groups.

Example:

Field group 1:

price 1+price2+price3*0,183=Total (also custom field)

Field group 2:

Total+price 4=Final price

The final price i need divide with another custom field (number of person)

Final price/persons=Price per person

Is it possible? If yes, I will be very happy ?

Thank you!!!!

I've posted similar thread in Toolset Professional Support, so look at on it (moderator answers)

https://toolset.com/forums/topic/post-fields-calculations/

#459684

Dear Renato,

As the threads you mentioned above, it needs custom codes, I suggest you follow the this thread to setup your custom shortcode:
https://toolset.com/forums/topic/calculator/#post-24976

If you needs more assistance for it, please duplicate same problem in a test site, and fill below private detail box with login details. also point out the problem page URL, and where I can edit your PHP codes, I need a live website to test and debug. thanks

#460008

Yes, it is OK, Please update this thread when your test site is ready. thanks

#461003

Thanks for the details, I have modified below in your website:
1) Modify the post type "Yachts", enable the option "Editor", then we can debug the codes in a single "Yachts" post
hidden link
2) modify the post:
hidden link
setup a demo code in the content:

Price per week 27 * Yacht commission <br />
= [types field="price-per-week-27"][/types] * [types field="yacht-commission"][/types] <br />
= [wpv-calculate] [types field="price-per-week-27"][/types] * [types field="yacht-commission"][/types] [/wpv-calculate]

3) Add below codes in the theme/functions.php:

add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts,$content=null) {
$content = do_shortcode($content);
$content = eval("return $content;");
return round($content, 2);
}

see the result:
hidden link
It is only a demo, you will need to customize it as what you want.

#461037

Thank you Luo!

Do I need to put this code to every single item or is there a way to add one calculation for all items? Maybe in conditional display?
Question: Is there any way to include calculated result in further calculation?

Thanks so much!

Regards

#461059

Q1) Do I need to put this code to every single item or is there a way to add one calculation for all items? Maybe in conditional display?
It depends on your self, if you need to use same codes for all single item(post), I suggest you setup a content template for those single item(post), and put your custom codes into the content template, then all single item will be able to display it.
see our document:
Content Templates – WordPress Custom Page Template Without PHP
https://toolset.com/documentation/user-guides/view-templates/

Q2) Is there any way to include calculated result in further calculation?
Above shortcodes can only display the calculated result in the front-end, it can not store the result into database, and it is a new question, which is different from your original question:
https://toolset.com/forums/topic/fields-calculation/#post-459475
And it needs custom codes too.

If the original question is resolved, please create new thread for new question, this will help other users to find the answers. thanks

#461585

Hello, thanks for reply. But...

I have custom php template for single post and post listing. Is the same procedure for this?

Thank you

#462112

If you need to use PHP codes, please try with wordpress function do_shortcode():
https://developer.wordpress.org/reference/functions/do_shortcode/

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.