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

This topic contains 2 replies, has 2 voices, and was last updated by  designerabreu@gmail.com 1 month, 2 weeks ago.

  • Creator
    Topic
  • #13961
    Resolved
    designerabreu@gmail.com
    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #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);
    } );
    #14349

    Works fine. Thanks a lot

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.