Support » Plugin: GiveWP - Donation Plugin and Fundraising Platform » Custom Email Tag Not Working

  • Resolved tgidev

    (@tgidev)


    I need to create a custom email tag that displays the net payment amount after Stripe fees.

    I followed the instructions on this page: https://givewp.com/documentation/developers/how-to-add-custom-email-tags/

    This is the code I ended up with. I added it to my theme’s functions.php file.

    // Adds a Custom "Payment Net" Tag
    function donation_net_amount_referral_tag() {
    	give_add_email_tag(
    		array(
    			'tag'      => 'payment_net', // The tag name.
    			'desc'     => __( 'The net payment for this donation (after fees).', 'give' ), // For admins.
    			'func'     => 'donation_net_amount', // 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', 'donation_net_amount_referral_tag' );
    
    function donation_net_amount( $tag_args ) {
    
    	// Update get meta request to get your custom data. You can pull from payment meta, donor meta, or other custom meta.
    	$net_payment = give_get_meta( $tag_args['payment_id'], 'payment_total', true );
    	$fees = ($net_payment * .029) + .3;
    	$net_payment = $net_payment - $fees;
    	$output = wp_kses_post( $net_payment );
    
    	return $output;
    }

    However, when I add the new email tag to a donation email and preview the email, all that shows is the tag name, not the value. Can I get some help figuring out what is wrong with my code? Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Ben Meredith

    (@benmeredithgmailcom)

    Hi there,

    Two things are improvable on that snippet. First, the meta name is _give_payment_total

    Next, you need to fomat the amount so that it rounds off to the correct number of decimal places.

    Here’s the whole code:

    
    // Adds a Custom "Payment Net" Tag
    function donation_net_amount_referral_tag() {
    	give_add_email_tag(
    		array(
    			'tag'      => 'payment_net', // The tag name.
    			'desc'     => __( 'The net payment for this donation (after fees).', 'give' ), // For admins.
    			'func'     => 'donation_net_amount', // 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', 'donation_net_amount_referral_tag' );
    function donation_net_amount( $tag_args ) {
    	// Update get meta request to get your custom data. You can pull from payment meta, donor meta, or other custom meta.
    	$net_payment = give_get_meta( $tag_args['payment_id'], '_give_payment_total', true );
    	$fees = ($net_payment * .029) + .3;
    	$net_payment = $net_payment - $fees;
    	$output = give_format_amount( wp_kses_post( $net_payment ) );
    	return $output;
    }
    

    Let me know if that doesn’t work. I tested it on my test installation.

    That worked perfectly. Thanks much I appreciate the help.

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