Skip Navigation

[Resolved] Field calculation

This support ticket is created 3 years, 4 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 8 replies, has 2 voices.

Last updated by Lisa Boyd 3 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2192339

I don’t know if this is possible or not. I’m importing a price list into custom fields. I need another field that takes whatever is in the price field and increases it by 20% for warranty pricing. Do you know how I can do that?

#2192699

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

- Can you please tell me how exactly you are importing the price list?

Do you want to increase the price by 20% based on the available value when you display it on frontend or you want to save the increased value by 20% to another custom field - if yes, do you want to increase the price field value by 20% when user publish/save the post?

#2192925

We are using Ultimate CSV Importer Pro to import a xml file daily at 6pm. Every time the importer runs, it removes all of the records and imports the file new into custom post type fields. A potential issue is that the price field is being imported as a text field not a number field because the file contains the dollar sign already.

I'm not sure which option would be better for performance if either are still an option. If the calculation is saved to another custom field, then that calculation would need to be performed after every import as the price may change. If there's a way to get it to show on the frontend based on the available value without that causing any performance issues, that would probably be the best option. Right now there are 779 prices that would need to be calculated.

#2193467

Minesh
Supporter

Languages: English (English )

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

There are two things - if you want to run some code after the import process has been done, you will have to check with the "Ultimate CSV Importer Pro" plugin support what action/hooks you can run after the import based on the imported data.

If you agree to display the calculated price based on custom shortcode when the content/post is displyed on the frontend then you will have to write the custom shortcode where we can grab the existing price field value and do the calculation on that price and return the calculated price.

#2193965

If we go with the 2nd option, can you help with writing the code or do you have developers you recommend?

#2194523

Minesh
Supporter

Languages: English (English )

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

Can you please tell at what place exactly on the frontend you want to display the calculated price and based on the what field you want to calculate the price.

Can you please share problem URL and admin access details.

*** 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.

#2194893

Minesh
Supporter

Languages: English (English )

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

I've added the following shortcode to the "Custom Code" section offered by Toolset:
=> hidden link

add_shortcode('wpv-calculated-price', 'func_calculated_price');
function func_calculated_price($atts,$content=null) {
global $post;
	$value = 	get_post_meta($post->ID,'wpcf-as-is-price',true);  
    $cal_value = ($value * $atts['increaseby']);
    return  $cal_value;
}

And I've called the above shortcode from the loop content template:
=> hidden link

<td> [wpv-calculated-price increaseby="1.2"]</td>

You can change the increaseby shortcode attribute value anytime as per your requirement, as you noticed its currently set as 1.2 as it's a dynamic.

Can you please confirm it works as expected.\

#2194949

This is exactly what I needed 🙂 Would it be possible to limit the calculation to 2 decimal points?

-- Edited to add I figured out how to round it to 2 decimal places 🙂 Thanks again for your help!

#2194959

My issue is resolved now. Thank you!