Custom Fields
Support Meta Box Builder Meta box fields as stock info?

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 3 weeks, 1 day ago.

  • Creator
  • #13961

    Meta box as stock info

    Hello, my meta box contains 4 numeric fields.
    1. Main stock
    2. Stock to sell
    3. Stock to give
    4. Stock to offer

    Is it possible or is there any way that the sum of the values ​​in fields 2,3 and 4 can never exceed the number indicated in field 1?

    And the possibility of a field that is sum of the values ​​of fields 1,2 and 3.

    Thank you for your help
    best regards

Viewing 1 replies (of 1 total)
  • Author
  • #13978

    Anh Tran


    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);
    } );
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.