Custom Fields
Re-Envisioned
Support Meta Box Builder Meta box fields as stock info? Reply To: Meta box fields as stock info?

#13978

Anh Tran
Keymaster

Hi,

Regarding the first option, to add constraints between fields, I think the only way to do that is with custom JS.

To save sum of some fields, please use rwmb_after_save_post hook. Here you can get fields’ values and update the sum to another field:

add_action( 'rwmb_after_save_post', function( $post_id ) {
    $field_1 = get_post_meta( $post_id, 'field_1', true );
    $field_2 = get_post_meta( $post_id, 'field_2', true );
    $field_3 = get_post_meta( $post_id, 'field_3', true );

    $sum = $field_1 + $field_2 + $field_3;
    update_post_meta( $post_id, 'sum', $sum);
} );