Hi @magnus1043,
My apologies for not responding sooner. You may already have found a solution or reached out to our support team, but for others who arrive here wondering the same thing, I’ll explain how to add a donate button with Charitable.
First off, all donations in Charitable are made to campaigns, so a campaign will be needed. Charitable doesn’t have a simple donate button out of the box; instead the donate buttons are shown on the campaign pages or when displaying a set of campaigns in a grid using the [campaigns] shortcode.
When you have set up your campaign, you can find the donation form by viewing the campaign and then clicking “Donate”. You can then use the URL of the donation form page elsewhere in your site to direct people to your donation form. For example:
Donate
Whether that displays as a button depends a bit on your WordPress theme. If it doesn’t, you can instead add a donate button shortcode to your website using a little bit of code:
/**
* To add a shortcode to display a campaign's donate button, include this function below.
*
* @param array $atts User-defined shortcode attributes.
* @return string
*/
function ed_charitable_campaign_donate_button_shortcode( $atts ) {
if ( ! array_key_exists( 'campaign_id', $atts ) ) {
return '';
}
// Get the campaign.
$campaign = charitable_get_campaign( $atts['campaign_id'] );
// Add the donate modal window to the footer. This is invisible until the button is clicked.
add_action( 'wp_footer', function() use ( $campaign ) {
charitable_template( 'campaign/donate-modal-window.php', array( 'campaign' => $campaign ) );
} );
ob_start();
// Render the donate button.
charitable_template_donate_button( $campaign );
// Load scripts that are required for the modal to work.
Charitable_Public::get_instance()->enqueue_donation_form_scripts();
return ob_get_clean();
}
add_shortcode( 'charitable_donate_button', 'ed_charitable_campaign_donate_button_shortcode' );
There are a few ways you can add code like this; we’ve written a guide here covering off the various options.
Once you have that code added, you can display a button like this:
[charitable_donate_button campaign_id=123]
Just replace 123 with the ID of your campaign.
One nice thing about the shortcode above is that if you’re setting the donation form to appear in the modal window, that will work automatically too.
Cheers,
Eric
-
This reply was modified 2 years, 8 months ago by Eric Daams.