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/
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
Yes, it is OK, Please update this thread when your test site is ready. thanks
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.
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
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
Hello, thanks for reply. But...
I have custom php template for single post and post listing. Is the same procedure for this?
Thank you
If you need to use PHP codes, please try with wordpress function do_shortcode():
https://developer.wordpress.org/reference/functions/do_shortcode/