Created
February 23, 2024 07:38
-
-
Save LaxusCroco/1c48be6af7ee745f9d5af557e2c5439c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//add custom callback to calculate the percentage between two fields// | |
add_filter( 'jet-engine-calculated-callback/config', function( $callbacks = array() ) { | |
$callbacks['calculate_percent_callback'] = function( $field_value, $fields ) { | |
$additional_field = jet_engine()->listings->data->get_meta( $fields ); | |
if ( $field_value <= 0 || $additional_field <= 0 ) { | |
return; | |
} | |
$result = ( 1 - $field_value / $additional_field ); | |
$result = $result * 100; | |
return $result; | |
}; | |
return $callbacks; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment