Hi,
orderby => $fee
This is wrong.
We can’t do order by like this.
We can orderby only on that values which is saved in the Database.
1st way
Fetch the data in the simple way, and store in the Array.
And we can change the the order as per our requirements.
2nd way
add_action( 'transition_post_status', 'wp_status_publish', 10, 3 );
function wp_status_publish( $new_status, $old_status, $post ) {
if ( $new_status == 'publish' && $old_status == 'auto-draft' ) {
$id = $post->ID;
$type = get_post_type( $id );
$meta_check = get_post_meta($id, 'commission_added', true);
if( $type == 'ficha_vehiculo' && $meta_check != "yes"){
$price = get_field('price');
// Your Calculations
$temp = ((discount/100)*$price);
$discount = $price-$temp;
$commission=1.33/100;
$fee = (($discount*$commission)+$discount)/120;
update_post_meta( $id, 'commission_added', 'yes', true );
add_post_meta( $id, ''commission', $commission, true );
}
update_post_meta( $id, 'commission_added', 'yes', true );
}
}
Above code is executed when we published the New Post from Auto-Draft.
And also above code is add the meta of Calculated Commission in current Post.
For this we use “transition_post_status” Hook.
With this you can get all the details related to post using Post ID.
Now, You can fetch the data with OrderBy on Commission(Meta,which is added in above steps).
2nd way is better
And Sorry for late reply.