[Forminator Pro] Event registration form : add custom field as price unit

Hi there!
I’m quite stuck with my situation. Here is my demo page : dev.collectifweb.ca/secondsouffle/formation/shine-my-life-formation-grand-public/

I created some forms for people to register on an event.
So basically there is a :
QTY PRICE (number of participant)
UNIT PRICE (custom field on the post)
TOTAL (calculation field)

I’d like to know how to generate a UNIT PRICE field, so basically autopopulate a number field with the event price.
The event price is set as a custom field named prix.
Can you help me on this?

And also, how can I “lock” this field so people can’t change it?
I’m ok to change this field as a hidden field but as I saw, we can’t use calculation on hidden field.

Thanks

  • Predrag Dubajic
    • Support

    Hi Alexandre Alves ,

    Calculation fields can also use numbers in calculations, meaning that you don’t need to use only fields in there.
    What that means is that you can have your number of participants added in the calculation field and then simply multiply it by the value of your ticket, for example, let’s say your ticket is $10, your calculation field would look something like this:
    {number-1}*10
    [attachments are only viewable by logged-in members]

    This kind of setup will also not show anything for the visitors regarding the price, but if you wish to show the fixed price as well you can simply use an HTML field and write the price in there, it can then look something like this:
    [attachments are only viewable by logged-in members]

    Let us know if that’s what you wanted to do or if you require some further assistance.

    Best regards,
    Predrag

  • Alexandre Alves
    • Floppy disk

    Hi there!
    thanks for your answer but that is not what I’m asking for.
    Price is set by a custom field on the post itself.
    So my calculation would be :
    Number of participant * custom-field-price = total

    I’m looking to send the custom field value to Forminator for this calculation.

    Thanks

  • Predrag Dubajic
    • Support

    Hi Alexandre,

    Thanks for the additional info, I missed at first how exactly this should work but I do understand it now. I’ve tried testing a couple of solutions by using ACF on my test installation but I’m afraid that I was unable to find a proper way to do this.

    I have tasked this for our devs so they can check it out and see if there’s a workaround that could be used to accomplish this kind of setup.
    Please note that developer response might be slower than usual staff response, so we appreciate your patience on this.

    Best regards,
    Predrag

  • Maciej Palmowski
    • Recruit

    Hi Alexandre Alves

    I was able to prepare a snippet for you.

    First some preparations:
    – create a custom field – I called mine “price”, but you can call it whatever you like
    – add a class to CSS:

    
    .hide-field{
    display: none;
    }
    

    – in Forminator create a number field with this class above.
    – copy this code to wp-content/mu-plugins:

    
    add_filter(
    	'forminator_field_markup',
    	function( $html, $data ) {
    		// Change number field name.
    		if ( 'number-2' === $data['element_id'] ) {
    
    			// Change the ACF field name.
    			$field = get_field( 'price' );
    
    			if ( $field ) {
    				$dom = new DOMDocument();
    				$dom->loadHTML( $html );
    				$inputs = $dom->getElementsByTagName( 'input' );
    
    				foreach ( $inputs as $input ) {
    					$input->setAttribute( 'value', $field );
                                               $input->setAttribute( 'readonly', 'readonly' );
    				}
    				$html = $dom->saveHTML();
    			}
    		}
    
    		return $html;
    
    	},
    	10,
    	2
    );
    

    I added comments what value may need to be change. And that’s all :slight_smile: I hope it will work correctly.