Is it possible for users to receive notifications when a donations is made on their page?

Individuals have been asking if it is possible to receive notifications when a payment is submitted on their page. Is this something that is already available or would tweaks be necessary to get this working? I'm not apposed to modifying the plugin if I can be pointed in the right direction.

I was thinking that it could be done by creating a dummy user for each of the donations pages, adding that user as the author of the page and then sending a notification to the email attached to the user. A thank you email is already being sent to guests when they submit a payment. Is it possible to hook into this somehow?

Alternatively just a simple email input field could also work but may require a little more coding.

  • Ivan

    Hey Market Mechanics,

    Hope you are well today.

    Currently there is no way for this out of the box.
    If you decie to give it a go with changing the plugin files. You can do the fallowing. Navigate to the plugin folder and open file fundraiser.php (better make copy of it before this)

    Then you will need to to line 942 and find the fallowing code

    $this->create_thank_you($funder_id,$transaction);

    And add right after it this line -

    $this->send_admin_notification($funder_id,$transaction,$post_title);

    So it should like this

    $this->create_thank_you($funder_id,$transaction);
     $this->send_admin_notification($funder_id,$transaction,$post_title);

    Then go to line 928 and add this code

    function send_admin_notification($funder_id, $trans = false,$fund) {
    		if($trans != false) {
    
    			$donor = $trans['first_name'] . ' ' . $trans['last_name'];
    			$donation_amount = $this->format_currency('',$trans['gross'], 1);
    			$donor_email = $trans['payer_email'];
    
    			$recurring = 'One-Time';
    			if(isset($trans['cycle'])) {
    				 $recurring = $trans['cycle'];
    			}
    
    			$to = $funder_id->user_email;
    			$subject = "Donation Received from " . $donor;
    	                $headers = 'From: "Fundraising" <none@none.none>';
    			$message = "We have received a new donation from " . $donor . "!\n";
    			$message .= "Amount: " . $donation_amount . "\n";
    			$message .= "Fund: " . $fund . "\n";
    			$message .= "Donor Email: " . $donor_email . "\n";
    			$message .= "Recurrence: " . $recurring;
    
    			//send email notification
    			wp_mail($to, $subject, $message, $headers);
    		}
    	}

    I haven't tested this code so if you decide to edit the plugin, please be adviced.
    Also you will lose any changes on update.

    Many thanks,
    Ivan

  • Jude

    Hello there @Market Mechanics,

    There are many ways to do this, but they all require at-least some modification in the plugin core. My colleague @Ivan Denkov gave you the easiest solution to this. I am going to be building on top of that.

    Here are the steps to get this working.

    1) Create a user with email address of the person who gets the donation. Assign this user as the author of the Fundraiser post (Just as you described)

    2) Make a modification as Ivan suggested. See Below :

    $this->create_thank_you($funder_id,$transaction);
     $this->send_admin_notification($funder_id,$transaction,$post_title);

    This can be found in line 950 in the code (fundraiser.php)

    3) Add this function ( Note this is different from above) to the file

    function send_admin_notification($funder_id, $trans = false, $fund) {
    		if($trans != false) {
    
    			$donor = $trans['first_name'] . ' ' . $trans['last_name'];
    			$donation_amount = $this->format_currency('',$trans['gross'], 1);
    			$donor_email = $trans['payer_email'];
    
    			$recurring = 'One-Time';
    			if(isset($trans['cycle'])) {
    				 $recurring = $trans['cycle'];
    			}
    
    			$to = the_author_meta( 'user_email', $funder_id )
    			$subject = "Donation Received from " . $donor;
    	        $headers = 'From: "Fundraising" <none@none.none>';
    			$message = "We have received a new donation from " . $donor . "!\n";
    			$message .= "Amount: " . $donation_amount . "\n";
    			$message .= "Fund: " . $fund . "\n";
    			$message .= "Donor Email: " . $donor_email . "\n";
    			$message .= "Recurrence: " . $recurring;
    
    			//send email notification
    			wp_mail($to, $subject, $message, $headers);
    		}

    Alternative Method

    You can create a field in the wp_postmeta table like recipient_email, and put the email address there. And once the transaction is successful you can add a hook to maybe

    do_action('wdf_gateway_confirm_'.$_SESSION['wdf_gateway']);

    Note that this requires more code and is harder to maintain with updates. Hope this helped

    Cheers
    Jude

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.