Skip Navigation

[Resolved] Calculator of selectors and other post fields

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to calculate total of CRED form field values and display total in email notification

Solution:
To calculate the Total, you need to add the custom shortcode to your current theme's functions.php file and pass the values as argument and shortcode should return the total.
You should add the custom shortcode to CRED form's email body as required.

you can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/calculator-of-selectors-and-other-post-fields/#post-626113

Relevant Documentation:

This support ticket is created 6 years, 8 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.

Our next available supporter will start replying to tickets in about 2.03 hours from now. Thank you for your understanding.

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 4 replies, has 2 voices.

Last updated by martinH-10 6 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#625106
screenshot 1.png

I am trying to: Use custom post fields in CRED form and then calculate the sum of them in email.

Link to a page where the issue can be seen: hidden link

I expected to see: SUM of custom field content

Instead, I got: No Items Found

I am using custom post fields of 2 types in form - Radio and Select. Every option has a name in Display text and a number in Custom field content. (screenshot 1)

I have an shortcode calculate included in views settings and located in functions.php:

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

Then I made a view with this formulation:

[calculate]
[types field='velikost-linky' output='raw'][/types] + [types field='odkapavac' output='raw'][/types] + [types field='baterie' output='raw'][/types] + [types field='dvouzasuvka' output='raw'][/types] + [types field='svitidlo' output='raw'][/types]
[/calculate]

and i put this view in the response e-mail to user who fill the form.

Idea is, that user select the custom inventory of kitchen, wich has a custom prices and in e-mail recieves the recapitulation and the sum of all radio button and selector content.

But it show only "No items found in email". It is propably because in the view is not configured correctly.

#625148

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - as I understand, basically you want to calculate the selected option values sum and display it within the email body - correct? I think you do not required to use view's here.

Could you please share CRED form URL and I'm happy to help you further.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#625279

Minesh
Supporter

Languages: English (English )

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

Thanks for sharing access details but unfortunately its not working at this end. Could you please send me working wp-admin access details - also, FTP access details are required to add custom shortcode as I need to interact with your theme's functions.php file.

Please send me working wp-admin and FTP details.

Additionally - you did not confirm following thing:
"As I understand, basically you want to calculate the selected option values sum and display it within the email body - correct?"

#626113

Minesh
Supporter

Languages: English (English )

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

Well - I've modified the shortcode as given under:

function calculate_shortcode($atts,$content=null) {
    $content = wpv_do_shortcode($content);
	$content = explode(",",$content);
	$content = array_sum($content);
   
    return $content;
    }
  add_shortcode('calculate', 'calculate_shortcode');

And I've added this shortcode directly to your email body as given under:

[calculate][types field='velikost-linky' output='raw'][/types],[types field='odkapavac' output='raw'][/types],[types field='baterie' output='raw'][/types],[types field='dvouzasuvka' output='raw'][/types],[types field='svitidlo' output='raw'][/types][/calculate]

You should remove view added to email body instead use use - I already added it to email body but you just adjust where you needed.

#626125

Thank you very much! Working like a charm!