Meta box fields as stock info?

Support MB Builder Meta box fields as stock info?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13961
    designerabreu@gmail.com[email protected]
    Participant

    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

    #13978
    Anh TranAnh 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);
    } );
    #14349
    designerabreu@gmail.com[email protected]
    Participant

    Works fine. Thanks a lot

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