The code looks ok to me. Where isn’t this working as you’d expect?
Cheers,
Eric
Thread Starter
rdosza
(@rdosza)
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
(@rdosza)
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.
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/
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
(@rdosza)
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.
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