Home / Admin / Remove Gateway Choice On A Campaign/Donation Page
Duplicate Snippet

Embed Snippet on Your Site

Remove Gateway Choice On A Campaign/Donation Page

This shows how you can detect what page/campaign you are on and remove a gateway from the list of active gateways specific to that campaign In theory this allows you some control in what gateways are available (or not) for certain campaigns on the same site.

Code Preview
php
<?php
// add this snippet to functions.php in your theme
add_filter( 'charitable_active_gateways', 'charitable_change_gateways_per_campaign', 10, 1 );
function charitable_change_gateways_per_campaign( $gateways ) {
	global $post;
	// $gateways will be an array similar to this:
	// [offline] => Charitable_Gateway_Offline
	// [stripe] => Charitable_Gateway_Stripe_AM
	if ( ! empty( $post ) && 'campaign' == $post->post_type && '126' == $post->ID ) {
		// Do not offer stripe as a gateway for campaign with the ID of 126.
		unset( $gateways['stripe'] ); // This removes the stripe gateway from the active gateway array.
	}
	// Note: if you remove a gateway and one remains, remember you won't be shown a choice on the donation form.
	return $gateways;
}

Comments

Add a Comment