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

  • 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 2 replies - 1 through 2 (of 2 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);
    } );

    Works fine. Thanks a lot

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.