Home / Admin / Add A Default Campaign Custom Amount
Duplicate Snippet

Embed Snippet on Your Site

Add A Default Campaign Custom Amount

Return a "default" amount if there isn't one isn't set in the session. Read all notes in the comments in the code to understand the cons.

Code Preview
php
<?php
add_filter( 'charitable_session_donation_amount', 'example_get_donation_amount_in_session', 999, 2 );
function example_get_donation_amount_in_session( $amount = false, $campaign = false ) {
	// If the donation amount is not set in the session, return the default amount.
	// WARNING: Setting a default amount here will override any default amounts that might be set in the Charitable settings.
	// ALSO NOTE: This will only work for donations made via the donation form. It will not work for donations made via the admin.
	// FINALLY: Setting a default amount for the user can be a bad idea, as it can lead to accidental donation amounts.
	if ( ! $amount ) {
		return 100;
	}
	// Otherwise, return the amount.
	return $amount;
}

Comments

Add a Comment