Title: Extending a Charitable Class
Last modified: October 19, 2016

---

# Extending a Charitable Class

 *  [rdosza](https://wordpress.org/support/users/rdosza/)
 * (@rdosza)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/)
 * Hi Eric,
 * I am trying to extend a Charitable class (both in functions.php and in a plugin)
   without success. My attempt was:
 *     ```
       Class Custom_Charitable_Campaign extends Charitable_Campaign {
       	public function get_donation_summary() {
                       //custom get_donation_summary function
       	}
       	public function custom_function() {
                       //my custom function
       	}
       }
       $new_Custom_Charitable_Campaign = new Custom_Charitable_Campaign($post);
       ```
   
 * Could you tell me what I am doing wrong?
 * Thanks in advance!
    -  This topic was modified 9 years, 6 months ago by [rdosza](https://wordpress.org/support/users/rdosza/).

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

 *  [Eric Daams](https://wordpress.org/support/users/ericdaams/)
 * (@ericdaams)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/#post-8327022)
 * The code looks ok to me. Where isn’t this working as you’d expect?
 * Cheers,
    Eric
 *  Thread Starter [rdosza](https://wordpress.org/support/users/rdosza/)
 * (@rdosza)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/#post-8327271)
 * When I put it into functions.php, changes do not reflect. When I put it in a 
   custom plugin, I receive a fatal error message: “Fatal error: Class ‘Charitable_Campaign’
   not found in /…/wp-content/plugins/charitable-custom/charitable-custom.php on
   line 15”
 * For test purpose, I am just changing “donated” for “raised”. Here goes the code:
 *     ```
       	Class Custom_Charitable_Campaign extends Charitable_Campaign {
       		public function get_donation_summary() {
       			$currency_helper = charitable_get_currency_helper();
   
       			if ( $this->has_goal() ) {
       				$ret = sprintf( _x( '%s RAISED of %s goal', 'amount donated of goal', 'charitable' ),
       					'<span class="amount">' . $currency_helper->get_monetary_amount( $this->get_donated_amount() ) . '</span>',
       					'<span class="goal-amount">' . $currency_helper->get_monetary_amount( $this->get( 'goal' ) ) . '</span>'
       				);
       			} else {
       				$ret = sprintf( _x( '%s donated', 'amount donated', 'charitable' ),
       					'<span class="amount">' . $currency_helper->get_monetary_amount( $this->get_donated_amount() ) . '</span>'
       				);
       			}
   
       			return apply_filters( 'charitable_donation_summary', $ret, $this );
       		}
       	}
       	$new_Custom_Charitable_Campaign = new Custom_Charitable_Campaign($post);
       ```
   
 *  Thread Starter [rdosza](https://wordpress.org/support/users/rdosza/)
 * (@rdosza)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/#post-8327305)
 * Sorry, in a plugin the fatal error is due the fact that I forgot the “require_once”.
   Yet, when fixed, changes also do not reflect.
 *  [Eric Daams](https://wordpress.org/support/users/ericdaams/)
 * (@ericdaams)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/#post-8375215)
 * Creating this class on its own won’t change the text; you would need to change
   the class that is used when displaying the text, and that’s a bit more complicated.
 * If all you want to do is change the text, I’d recommend using Loco Translate 
   instead: [https://en-au.wordpress.org/plugins/loco-translate/](https://en-au.wordpress.org/plugins/loco-translate/)
 * It’s a translation plugin, but gives you an easy way to change the default phrases/
   words used in Charitable.
 * Cheers,
    Eric
 *  Thread Starter [rdosza](https://wordpress.org/support/users/rdosza/)
 * (@rdosza)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/#post-8375936)
 * Thanks but changing text was just an example for testing purpose. Even this particular
   class serves only as example for testing purposes. I just wanted to try to create
   some extensions but simply do not understand what I am doing wrong and why I 
   am not able extend Charitable_Campaign class.
 *  [Eric Daams](https://wordpress.org/support/users/ericdaams/)
 * (@ericdaams)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/#post-8389816)
 * Sorry, I guess I’m struggling to understand what you are trying to achieve. Why
   do you want to create a subclass of Charitable_Campaign? What do you want to 
   do with it and where do you want to integrate it?
 * cheers,
    eric

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

The topic ‘Extending a Charitable Class’ is closed to new replies.

 * ![](https://ps.w.org/charitable/assets/icon-128x128.jpg?rev=1225178)
 * [Charitable - Donation Plugin for WordPress - Fundraising with Recurring Donations & More](https://wordpress.org/plugins/charitable/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/charitable/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/charitable/)
 * [Active Topics](https://wordpress.org/support/plugin/charitable/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/charitable/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/charitable/reviews/)

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)

 * 6 replies
 * 2 participants
 * Last reply from: [Eric Daams](https://wordpress.org/support/users/ericdaams/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/extending-a-charitable-class/#post-8389816)
 * Status: not resolved