Skip to content

Instantly share code, notes, and snippets.

@LaxusCroco
Created February 23, 2024 07:38
Show Gist options
  • Save LaxusCroco/1c48be6af7ee745f9d5af557e2c5439c to your computer and use it in GitHub Desktop.
Save LaxusCroco/1c48be6af7ee745f9d5af557e2c5439c to your computer and use it in GitHub Desktop.
<?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