• Resolved vanessaflibustiers

    (@vanessaflibustiers)


    Bonjour,

    Est-il possible d’afficher des champs ACF dans forminator ?

    Plus précisément :
    J’ai un type de publication “Ateliers” construit avec différents champs ACF, dont un champs “prix”. J’utilise forminator pour que les internautes puissent s’inscrire à cet atelier, avec stripe.
    J’aimerais que le champs acf “Prix” puisse remonter dans forminator afin d’indiquer à stripe le montant à payer.

    Merci par avance pour votre aide
    Cordialement

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @vanessaflibustiers

    I hope you are doing good today.

    This should be possible with some custom coding as a mu-plugin.

    <?php
    add_filter( 'forminator_field_create_input', function( $html, $attr ){
    static $list_fields = [];	
    	if( ! $list_fields ){
    		global $post;
    		$post_id = is_numeric( $post ) ? $post : $post->ID;
    		$user_email = get_post_meta( $post_id, 'email', true );//get the email. In this case the email is the name of the ACF Field
    		$list_fields = array(
    			//'text-1' => get_the_title( $post ),
    			'email-1' => $user_email,
    		);
    		//You can add as many fields as you feel neccessary and use the post ID to get whatever custom meta data you need and add it to the array
    		//In this case I am getting the post title and email and adding it 
    	}
    	if( $list_fields && isset( $list_fields[ $attr['name'] ] ) ){
    		$html = str_replace('value="'. $attr['value'] .'"', 'value="'. $list_fields[ $attr['name'] ] .'"', $html );
    		//Add data to cariable and add it to form
    	}
    return $html;	
    },10, 2 );

    Of course this is an example and you will need to modify this code so it will fit your ACF fields.

    Must Use Plugins

    Kind Regards,
    Kris

    Thread Starter vanessaflibustiers

    (@vanessaflibustiers)

    Bonjour,

    Merci pour votre retour?
    Je ne suis pas très familière de ce langage, pourriez-vous m’adapter le code avec deux champs acf :

    “prix-adherent”
    “prix-non-adherent”

    Cela m’aidera à visualiser quels éléments je dois mettre à jour.

    Merci par avance

    Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @vanessaflibustiers

    Here is updated code but you’ll still need to make small adjustments (read below the code):

    <?php 
    
    add_filter( 'forminator_field_create_input', function( $html, $attr ){
    static $list_fields = [];	
    	if( ! $list_fields ){
    		global $post;
    		$post_id = is_numeric( $post ) ? $post : $post->ID;
    		
    		
    		// get fields values from DB		
    		$prix_adherent = get_post_meta( $post_id, 'prix-adherent', true );
    		$prix_non_adherent = get_post_meta( $post_id, 'prix-non-adherent', true );
    		
    		// map them to form fields
    		$list_fields = array(
    			'field-1' => $price_adherent,
    			'field-2' => $price_non_adherent,
    		);
    		//You can add as many fields as you feel neccessary and use the post ID to get whatever custom meta data you need and add it to the array
    		 
    	}
    	if( $list_fields && isset( $list_fields[ $attr['name'] ] ) ){
    		$html = str_replace('value="'. $attr['value'] .'"', 'value="'. $list_fields[ $attr['name'] ] .'"', $html );
    		//Add data to cariable and add it to form
    	}
    return $html;	
    },10, 2 );

    So these lines of the code are fetching data from the database – they are reading values from your custom fields:

    $prix_adherent = get_post_meta( $post_id, 'prix-adherent', true );
    $prix_non_adherent = get_post_meta( $post_id, 'prix-non-adherent', true );

    But you still need to change this part

    'field-1' => $price_adherent,
    'field-2' => $price_non_adherent,

    and replace the field-1 and field-2 with IDs of the form field that should have that value from ACF added. So for example if your price fields on form are “{currency-1}” and “{currency-2}” these lines should be changed to

    'currency-1' => $price_adherent,
    'currency-2' => $price_non_adherent,

    I hope this makes sense.

    Best regards,
    Adam

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @vanessaflibustiers ,

    We haven’t heard from you for over a week now, so it looks like you don’t need our assistance anymore.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

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

The topic ‘Forminator et ACF’ is closed to new replies.