Skip Navigation

[Resolved] Custom Fields Calculations

This support ticket is created 3 years, 1 month 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
- 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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by philipC-4 3 years ago.

Assisted by: Waqar.

Author
Posts
#2207165
Screen Shot 2021-10-25 at 11.28.24 AM.png
Screen Shot 2021-10-27 at 10.57.28 AM.png
Screen Shot 2021-10-27 at 10.24.43 AM.png

Tell us what you are trying to do?

Hello,

We have a custom code in place that was provided by your awesome support specialist Christian Cox. The code calculates all the custom fields that are selected on the post page.

We will have several forms that will need to have this feature. Currently, the Structural Systems form works perfectly.

We have duplicated the code and applied it to the new form "Electrical Systems" but when we "Activate" the code it breaks the website.

You will have to log in to view the pages and code, please let me know when it is safe to share login credentials.

Name of WORKING code:
cred_save_data.php

BROKEN CODE Name:
electrical_cred_save_data

FORM that is used to calculate custom fields:
hidden link

Test Post that will display calculations:
• Total Inspected
• Total Not Inspected
• Total Ok
• Total Deficient
hidden link

Is there a similar example that we can see? Please let me know when it is safe to share access credentials

What is the link to your site? hidden link

#2207683

Hi,

Thank you for contacting us and I'd be happy to assist.

When you duplicated the working code snippet, did you change the name of the function in the new code snippet? The same name function can't be used again and would result in an error.

For example, suppose, your first code snippet, had the function named "my_save_data_function":


add_action('cred_save_data', 'my_save_data_function',10,2);
function my_save_data_function($post_id, $form_data)
{
....
}

Now, when you'll duplicate it for some different form, you'll need to change the function name "my_save_data_function" to something else, to avoid the error:


add_action('cred_save_data', 'my_save_data_function_electrical',10,2);
function my_save_data_function_electrical($post_id, $form_data)
{
....
}

I hope this helps and in case the issue still persists, you're welcome to share temporary admin login details, in reply to this message.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2211151

Hello Waqar,

I wanted to make sure you received my previous reply.

Please let me know if you need any more information.

Thank you sir!

#2211553

Thank you for sharing these details.

During troubleshooting, I noticed that the field "Total Inspected Electrical" has slug "total-inspected-electric", but in the code snippet at line# 37, "total-inspected_electric" is used.
( note the use of _ instead of - before electric )

Please change that line from:


update_post_meta( $post_id, 'wpcf-total-inspected_electric', $total_inspected_electric );

To:


update_post_meta( $post_id, 'wpcf-total-inspected-electric', $total_inspected_electric );

#2212357

We appreciate all your help Waqar! My issue is resolved now. Thank you!