Skip Navigation

[Resolved] Store calculate shortcode result as field value

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

Last updated by jamesR-13 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2567803

I have created a shortcode that does calculations on two fields based on this:
https://toolset.com/forums/topic/calculate-shortcode/

The shortcode by itself works fine, however I need to store the result of the calculation in a field. When I try adding it as the default value I get a critical site error. I have registered the shortcode to be used as an argument in the settings.

Is there some other way I can/should be setting the value of the field to the shortcode output? Appreciate your help.

#2568075

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Its not clear to me where you want to assign the default value and where exactly you want to store it.

Can you please share problem URL where you want to apply the default value as well as admin access details and any other information that should help me.

*** 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 have set the next reply to private which means only you and I have access to it.

#2569099

Minesh
Supporter

Languages: English (English )

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

I checked the following page: hidden link

I do not find the field called "Special Item Line Total" which you mentioned where you want to store the total value. Is that field is not added to form? Do you want to store the total value to field called "Special Item Line Total" when you submit the form?

#2569311

So for testing let's look at requisition 7700:
hidden link

the form is called "Omni item" and it's only visible while the requisition is in draft status. I would like the field to be hidden for most users, and used only to store the value and do calculations, so I have added the field at the bottom of the form.

#2569323

Minesh
Supporter

Languages: English (English )

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

With the link you shared I can see there is a red page saying that there is an error:
=> This is an error… how embarassing.

I do not see the form.

#2569339

Someone had cancelled (trashed) that requisition. It has been restored. Try it now.

You have to select "Special Order" in the Type field for the Line item total field to be visible.

#2569353

Minesh
Supporter

Languages: English (English )

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

I see with the following order page: hidden link

I can see there are two order where total for one order is $1,001.51 and total for another order is: $444.66

So do you want to add those total amount $1,001.51 + $444.66 and add the total of those that is: $1446.17 to the "Special Item Line Total" field?

#2569357

What you are calling an 'order' is an item, and a child post of the requisition. The item post type has the custom field "Special Item Line Total" The 444.66 is the calculator shortcode value that I am trying to store in the custom field Special Item Line Total for that item post.

#2569363

To clarify, when I say "Draft status" i don't mean the wordpress publishing status, but the Requisition post type custom field called status having the value draft.

#2569379
code.png

So, looking at functions.php it appears I have started working on this on the PHP side in the past. Here's what I have. At a glance, it should do what I am trying to do. Can you help me figure out why it doesn't populate the field when a special order item is added? I'm attaching a screenshot showing the code and the line numbers in functions.php

#2570263

Minesh
Supporter

Languages: English (English )

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

I got that but still I'm having bit confusion that lets say for instance the following post:
- hidden link

With such post have multiple special Order items listed with above page in any case or all the time with such above post only one special order item will be there? Why I'm asking this because if there will be the case that multiple special order will be assigned then we will have to get those related posts and loop through those posts and calculate the sum of it.

If it will be only one Special Order item then what if I can get the value of field "Special Item Line Total" and copy that field value to the "Special Item Line Total" field on the form?
=> hidden link

#2570287
code.png

There may be more than one special order item on a requisition, but the shortcode in question is only calculating Quanity x Price for one special order item at a time and I just need to store that value in the Special Item Line Total for that individual Item post, not for multiple Item posts at a time.

The code in the attached screenshot should do what I am needing it to do but it isn't working, and I don't know why.

#2571763

Minesh
Supporter

Languages: English (English )

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

As you shared the details before:
- https://toolset.com/forums/topic/store-calculate-shortcode-result-as-field-value/#post-2569339

I do not see "Special Order" dropdown now with the problem URL you shared:
- hidden link

#2573699
ss.png

Special order isn't a dropdown, it's an option under the "Type" dropdown.

Screenshot attached.

#2574371

Minesh
Supporter

Languages: English (English )

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

Yes but the same"Type" dropdown I can not see with the following URL:
- hidden link

And another one is showing some critical error:
- hidden link

Why my doubt is there because you are displaying the order items with its respected totals using the view. So view can print multiple items. So lets say there are five order items and out of that five items only one is "Special Order" how come I know outside the view that out of those five items the X (for instance 4th) item is "Special Order" and that order item total you want to display with the "Type" dorpdown when I select the "Special Order".

Additionally - if we do not set the value with the "Type" dropdown and directly get the value using the get_post_meta() and set the value - is that ok or you want to set the value first using the "Type" dropdown?

If its a single post then it will be easy but the issue here is you are looping through the view's loop and want to get value of specific custom field outside the view's loop.