• Resolved mallamace

    (@mallamace)


    I have been following “How to Create Custom Form Fields” using GiveWP Code Snippets. I can see the custom code snippet upon purchase complete, but I cannot find where this data is stored or displayed within GiveWP.

    This is the example of code I’m using.

    add_action( 'give_fields_donation_form_before_personal_info', function( $collection ) {
        $collection->append(
            give_field( 'text', 'Occupation' )
                ->showInReceipt()
                ->label( __('Occupation') )
                ->emailtag('my-occupation-tag')
                ->minLength(2)
                ->maxLength(30)
                ->placeholder('Your Occupation')
                ->storeAsDonorMeta()
                ->required() // Could instead be marked as readOnly() (optional)
                ->helpText( __( 'If you are retired - include RETIRED.' ) )
        );
    });

    I followed this based on the example here:
    https://givewp.com/documentation/developers/how-to-create-custom-form-fields/

    I added emailtag() with ‘my-occupation-tag’ as the value, however I just get “Occupation: {my-occupation-tag}” back in my email without the value. I was thinking I could use {meta_donor_Occupation} based on what I read here:
    https://givewp.com/documentation/core/settings/emails/meta-email-tags/#other-examples
    but I read “Keep in mind that these meta email tags only output the value of the tag, not the label at all.”

    Can you please help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter mallamace

    (@mallamace)

    I found the stored Donor META data in phpMyAdmin ‘wp_xxxxxx_give_donormeta’ table, however I am still unable to retrieve this information into an email upon submit.

    If there is a way to retrieve the same information from within Donations WordPress admin this would also be acceptable solution.

    Pulling up phpMyAdmin is not practical.

    I’m also using Stripe payment if that helps.

    Thread Starter mallamace

    (@mallamace)

    One more try, but no luck with following:
    https://givewp.com/documentation/developers/how-to-add-custom-email-tags/

    This did not return any results

    /**
     * Adds a Custom "Occupation" Tag
     *
     * This function creates a custom GiveWP email template tag.
     */
    function my_custom_prefix_add_occupation_tag() {
    	give_add_email_tag(
    		array(
    			'tag'      => 'my-occupation-tag', // The tag name.
    			'desc'     => __( 'This outputs the Occupation', 'give' ), // For admins.
    			'func'     => 'my_custom_prefix_get_donation_occupation_info', // Callback to function below.
    			'context'  => 'general', // This tag can be for both admin and donor notifications.
    			'is_admin' => false, // default is false. This is here to simply display it as an option.
    		)
    	);
    }
    
    add_action( 'give_add_email_tags', 'my_custom_prefix_add_occupation_tag' );
    
    /**
     * Get Custom Occupation Message
     *
     * Example function that returns custom field data if present in payment_meta;
     * The example used here is in conjunction with the GiveWP documentation tutorials.
     *
     * @param array $tag_args Array of arguments
     *
     * @return string
     */
    function my_custom_prefix_get_donation_occupation_info( $tag_args ) {
    
    	// Update get meta request to get your custom data. You can pull from payment meta, donor meta, or other custom meta.
    	$my-occupation-tag = give_get_meta( $tag_args['payment_id'], 'give_occupation', true );
    	$output            = __( 'No Occupation message :(', 'give' ); // Fallback message. (optional)
    	
    	if ( ! empty( $my-occupation-tag ) ) {
    		$output = wp_kses_post( $my-occupation-tag );
    	}
    
    	return $output;
    }
    Plugin Support Rick Alday

    (@mrdaro)

    Hi @mallamace,

    I tested your snippet and the {my-occupation-tag} outputs the occupation without any additional code.
    Here’s a quick screencast to demonstrate: https://somup.com/c3Qr2oUCHu

    Triple-check that there are not typos in your email template. Also check the template in HTML view to make sure the formatting is not getting in the way.

    If you still cannot get it to work, the last snippet you posted should do the trick but you need to fix it a bit.

    The give_get_meta() function queries the donation meta, not the donor meta. So you need to get the donor id from the payment meta and then use that to query the donor meta for the value you are looking for.

    So change this line:
    $my-occupation-tag = give_get_meta( $tag_args['payment_id'], 'give_occupation', true );

    to this:

    $donorID = give_get_payment_meta($tag_args['payment_id'], '_give_payment_donor_id');
    $my-occupation-tag = Give()->donor_meta->get_meta($donorID, 'Occupation', true);

    Hope that helps.

    Plugin Support Rick Alday

    (@mrdaro)

    Hi there,

    Just checking in on this issue. Do you still need assistance here?

    If you still need help, reply and we’ll make sure everything is handled.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Emailing Custom Snippet Data’ is closed to new replies.