Custom Fields
Re-Envisioned
Support General Using Field Values in Calculations – 2 questions

  • Creator
    Topic
  • #12231
    Resolved @mindspark
    Participant

    Hi Anh – I’m using MB to create custom fields for a CPT ‘Pacakges’. The fields collect data that is then used to create a ‘Package’ so potential buyers can review a given restaurant that is for sale.

    Aside from the standard form fields included with MB AIO, I also need –

    Percentages (80%, 16%, etc)

    Question #1 – how can I implement fields that recognize numerical input as a percentage? I am using the number field now….

    I also need to create calculations based on field values (100 x 6% = 6). In addition to the data entry fields, I also need to display a few simple calculations to present financial data.

    Question #2 – how do I perform calculations and then display the result?

    thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #12267
    @mindspark
    Participant

    any updates here?

    #12286
    Anh Tran
    Keymaster

    Hi Neil,

    Question #1 – how can I implement fields that recognize numerical input as a percentage? I am using the number field now….

    It actually doesn’t. You need to write some description to the field to let users know it’s a percentage.

    Question #2 – how do I perform calculations and then display the result?

    When you insert the code to the front end, please add some calculation before that:

    $value = rwmb_meta( 'percentage' );
    $value = $value / 100 * $another_field_value;
    echo $value;

    If you’re using a page builder like Beaver Builder, I’d suggest writing a custom shortcode to put into a text module in BB. The shortcode might be like this (put in functions.php):

    add_shortcode( 'your_percentage', function( $atts, $content ) {
        $value = rwmb_meta( 'percentage' );
        $value = $value / 100 * $another_field_value;
        return $value;
    } );

    In a text module in BB, simply insert [your_percentage] and your result will appear.

    #12306
    @mindspark
    Participant

    Thanks Anh!

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