Skip to content

Instantly share code, notes, and snippets.

View ericnicolaas's full-sized avatar
🎯
Focusing

Eric Daams ericnicolaas

🎯
Focusing
View GitHub Profile
@ericnicolaas
ericnicolaas / functions.php
Last active May 22, 2020 05:10
Add "Waiver Agreement" fields to campaign form on initial submission
<?php
add_filter(
'charitable_campaign_submission_fields',
function( $fields, $form ) {
$waiver_fields = array(
'legend' => 'Liability Waiver and Release',
'type' => 'fieldset',
'fields' => array(
'waiver' => array(
'type' => 'paragraph',
@ericnicolaas
ericnicolaas / function.php
Created March 13, 2020 01:16
Adding new field to donations export based on custom campaign field
<?php
/**
* In this example, we add a custom field to campaigns, which is
* automatically included in the Donations export for donations
* to those campaigns.
*/
add_action(
'init',
function() {
/**
@ericnicolaas
ericnicolaas / functions.php
Created March 9, 2020 01:37
Add categories field to Fundraiser form
<?php
add_filter( 'charitable_fundraiser_submission_campaign_fields', function( $fields, Charitable_Ambassadors_Fundraiser_Form $form ) {
$parent_fields = $form->get_sanitized_campaign_form_fields( 'campaign-details' );
$fields['categories'] = $parent_fields['categories'];
return $fields;
}, 10, 2 );
@ericnicolaas
ericnicolaas / functions.php
Last active March 3, 2020 08:56
Customizing the team fundraiser form
<?php
/**
* Function to add a new field.
*
* Available sections:
*
* - recipient_fields
* - campaign_fields
* - user_fields
* - fundraiser_type_selection_fields
@ericnicolaas
ericnicolaas / function.php
Last active October 7, 2019 02:49
Include surplus of one campaign in total of another campaign
<?php
add_filter(
'charitable_campaign_donated_amount',
function( $amount, $campaign, $sanitize ) {
$new_campaign = 14;
$old_campaign = 135;
$old_goal = charitable_get_campaign( $old_campaign )->get_goal();
if ( $new_campaign == $campaign->ID ) {
// Get the combined total of the old & new campaigns.
@ericnicolaas
ericnicolaas / function.php
Last active July 11, 2019 03:45
Charitable - Add user fields to campaign Funds Recipient tab, with images displayed as thumbnails.
<?php
/**
* This example shows how to add extra fields of information to the Funds Recipient
* tab, which is displayed for all campaigns in the admin.
*
* In the example below, all of the fields in the User Details section of the frontend
* campaign form are added to the table. If you only want to add one or two fields,
* you can add them as follows:
$key = 'field-you-want-to-add';
@ericnicolaas
ericnicolaas / function.php
Created June 2, 2019 23:14
Add Campaign Manager capabilities to Editor role
add_action(
'init',
function() {
$campaign_manager = get_role( 'campaign_manager' );
$editor = get_role( 'editor' );
foreach ( $campaign_manager->capabilities as $cap => $has_cap ) {
if ( ! $has_cap ) {
continue;
}
@ericnicolaas
ericnicolaas / function.php
Created May 1, 2019 23:19
Charitable Ambassadors - Get suggested donations value
<?php
add_filter(
'charitable_campaign_submission_donation_options_fields',
function( $fields, $form ) {
$fields['suggested_donations']['value'] = $form->get_campaign_value( 'suggested_amounts' );
return $fields;
},
10,
2
);
@ericnicolaas
ericnicolaas / function.php
Created March 19, 2019 01:35
Show organization name instead of donor name
<?php
/**
* If you have a custom donation field where donors can
* enter their organization name, you may want to display
* the organization name instead of the donor's name
* in the donor widget/shortcode.
*
* @param string $name The donor's name.
* @param array $view_args A collection of arguments passed to the view.
* This includes the Charitable_Donor instance.
@ericnicolaas
ericnicolaas / edd-function.php
Last active February 4, 2019 06:18
Add an email tag for a custom Charitable campaign field
<?php
/**
* In Easy Digital Downloads, you can add your own email tags to include
* in purchase receipts & notifications.
*
* In this example, we add a tag that allows you to display the value of
* a custom 'campaign_email_content' field in Charitable. This is an optional
* follow-up to a tutorial published on our blog.
*
* @see https://www.wpcharitable.com/tutorial-how-to-add-campaign-specific-content-to-the-donation-receipt-email/