Tell us what you are trying to do?
I'm trying to create a function that populates a custom field based on a percentage value presented in one field (wpcf-commission-percent) and the value to find the percentage of (wpcf-property-price) creating a populated field (wpcf-percentage-commission-value). This is so I can show how much someone could earn if a house is sold.
The code I'm using currently is as follows ...........
<?php
/**
* New custom code snippet.
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
function calculate_commission( $post_ID ) {
if ( get_post_type( $post_ID ) == 'property' ) {
$commission_percent = get_post_meta($post_ID, 'wpcf-commission-percent', true);
$property_price = get_post_meta($post_ID, 'wpcf-property-price', true);
$commission_divider = $property_price / 100;
update_post_meta( $post_ID, 'wpcf-commission-divider', $commission_divider );
$commission_value = $commission_divider * $commission_percent;
update_post_meta( $post_ID, 'wpcf-percentage-commission-value', $commission_value );
}
}
add_action( 'save_post', 'calculate_commission', 99 );
Is there a similar example that we can see?
I built this based off of a previous example of something similar here ......
https://toolset.com/forums/topic/calculate-value-of-a-custom-field-based-on-other-custom-fields-values/
Any help would be greatly appreciated.
Ed