Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Matheus Martins

    (@matheusfd)

    Hi, @magamatt.

    I’m glad you reached out. I can certainly help you.

    When you have the need to add some kind of custom information to a specific form, you need to check the form ID before you add a custom field.

    Although we do not have a handy code snippet to do exactly that, I have an example that shows you how to translate a specific string on a form. With some editing, you can add a custom field based on the form ID. here is the example:

    https://github.com/impress-org/givewp-snippet-library/blob/master/translation-snippets/change-text-locally-per-form.php

    If you need assistance implementing custom PHP code on your website we have this guide: https://givewp.com/documentation/resources/adding-custom-functions-to-your-wordpress-website/.

    Please note that this code snippet is provided as an example of how you can extend GiveWP with code. It’s up to you to implement and customize to your liking. We cannot provide support for custom code on your website, only the code that we create and distribute.?

    Feel free to reach out to us if you have any further inquiries or require additional assistance. We’re always happy to help!

    Thread Starter magamatt

    (@magamatt)

    Hi Matheus, thank for your reply, below is the snippet I am using.

    Nnow I would like the additional field ‘cellular’ to be visible only in the form with ID 20023, how do I update my script?

    add_action( ‘give_fields_donation_form_after_personal_info’, function( $group ) {
    $group->append(
    give_field( ‘text’, ‘Cellular’ )
    ->showInReceipt()
    ->minLength(2)
    ->label( ( ‘Numero di cellulare’ )) ->maxLength(30) ->placeholder(‘Inserisci qui il numero di cellulare per facilitare le comunicazioni’) ->storeAsDonorMeta() ->helpText( ( ‘Inserisci qui il numero di cellulare per facilitare le comunicazioni’ ) ) //how this is displayed is up to the template, but if the template has help text displayed, this is how to set it.
    );
    });

    Plugin Support Matheus Martins

    (@matheusfd)

    Hi, @magamatt.

    Your code would look something like this:

    <?php 
    
    function my_custom_info( $translations, $text, $domain ) {
    
    	add_action( ‘give_fields_donation_form_after_personal_info’, function( $group ) {
    		$group->append(
    			give_field( ‘text’, ‘Cellular’ )
    			->showInReceipt()
    			->minLength(2)
    			->label( ( ‘Numero di cellulare’ ))
    			->maxLength(30)
    			->placeholder(‘Inserisci qui il numero di cellulare per facilitare le comunicazioni’)
    			->storeAsDonorMeta()
    			->helpText( ( ‘Inserisci qui il numero di cellulare per facilitare le comunicazioni’ ) ) //how this is displayed is up to the template, but if the template has help text displayed, this is how to set it.
    );
    	});	
    }
    
    /**
     * Conditional for gettext.
     *
     * @param $form_id
     */
    function my_give_confirm_form( $form_id ) {
    
    	// Change your FORM ID
    	if ( $form_id == 20023 ) {
    		add_filter( 'gettext', 'my_custom_info', 10, 3 );
    	}
    }
    
    add_action( 'give_pre_form_output', 'my_give_confirm_form', 10, 1 );

    If you need some dev assistance, we encourage you to reach out to our friends at Codeable.io (https://go.givewp.com/codeable). They are WP experts and will surely help you.

    Thanks for using GiveWP! Have a great day.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom field on a specific donation form’ is closed to new replies.