Skip Navigation

[Resolved] Calculate value of a custom field based on related custom fields values

This support ticket is created 3 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 3 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1772503

Tell us what you are trying to do?
I have a CPT Domain with a many-to-many relationship to the CPT Services.
CPT Services has a numerical field "monthly-cost".
One of the CPT Services entries is "Email" and has a "monthly-cost" of $2.00
One of the CPT Services entries is "Hosting" and has a "monthly-cost" of $2.00
CPT Domain has a numerical field "domain-monthly-cost".
One of the CPT Domain entries is "Test.com" and is related to the CPT Services "Email" and "Hosting".

I am trying to calculate "domain-monthly-cost" = "Email" "monthly-cost" + "Hosting" "monthly-cost"

Is there any documentation that you are following? https://toolset.com/forums/topic/calculate-value-of-a-custom-field-based-on-other-custom-fields-values/

What is the link to your site? hidden link

#1773169

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know here that at what action you want to calculate the "domain-monthly-cost". When you submit the "Domain" post from the backend admin or at any other action?

#1773313

Hi. I would like it to calculate when I submit from the backend and when I submit a form (which I haven't created yet but will allow me to enter Domain information).

#1773315

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

when you say in backend - do you mean when editing single post of post type "Domain"?

If yes - you will require to use the save_post action hook:
=> https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/

And to get the related-post information you will require to use the Toolset post-relationship API function:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

Once you get this information, you should get the value of your desired field and make calculation and save the total value to your desired field.

If you will require further help, please let me know.

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