Created
August 15, 2018 11:54
-
-
Save kimcoleman/93c681c0cc741aef8037e12c8b5dd0ac to your computer and use it in GitHub Desktop.
Code to collect additional donations to specific categories at checkout, display fields on admin profile view, Members List, and include in Members List CSV Export.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Code to collect additional donations to specific categories or causes using the | |
* Register Helper Add On for Paid Memberships Pro. | |
* This is a different/independent approach from using the Donations Add On for Paid Memberships Pro. | |
*/ | |
function my_pmpro_checkout_level($level) | |
{ | |
$donation = 0; | |
if(!empty($_REQUEST['donation_general_npso_gift']) && is_numeric($_REQUEST['donation_general_npso_gift'])) | |
{ | |
// $level->initial_payment = $level->initial_payment + ; | |
$donation = $donation + $_REQUEST['donation_general_npso_gift']; | |
} | |
if(!empty($_REQUEST['donation_rare_and_endangered_plant_fund']) && is_numeric($_REQUEST['donation_rare_and_endangered_plant_fund'])) | |
{ | |
// $level->initial_payment = $level->initial_payment + ; | |
$donation = $donation + $_REQUEST['donation_rare_and_endangered_plant_fund']; | |
} | |
if(!empty($_REQUEST['donation_leighton_ho_memorial_fund']) && is_numeric($_REQUEST['donation_leighton_ho_memorial_fund'])) | |
{ | |
$donation = $donation + $_REQUEST['donation_leighton_ho_memorial_fund']; | |
} | |
$level->initial_payment = $level->initial_payment + $donation; | |
return $level; | |
} | |
add_filter("pmpro_checkout_level", "my_pmpro_checkout_level"); | |
/* | |
* Donation Fields for lisagrayarea Forum Thread | |
*/ | |
function my_pmprorh_init() | |
{ | |
//don't break if Register Helper is not loaded | |
if(!function_exists( 'pmprorh_add_registration_field' )) { | |
return false; | |
} | |
//define the fields | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'donation_general_npso_gift', | |
'text', | |
array( | |
'label' => 'General NPSO Gift', | |
'size' => 7, | |
'profile' => 'only_admin', | |
'memberslistcsv' => true, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'donation_rare_and_endangered_plant_fund', | |
'text', | |
array( | |
'label' => 'Rare and Endangered Plant Conservation Fund', | |
'size' => 7, | |
'profile' => 'only_admin', | |
'memberslistcsv' => true, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'donation_leighton_ho_memorial_fund', | |
'text', | |
array( | |
'label' => 'Leighton Ho Memorial Field Botany Fund', | |
'size' => 7, | |
'profile' => 'only_admin', | |
'memberslistcsv' => true, | |
) | |
); | |
pmprorh_add_checkout_box("donations", "Donations"); | |
//add the fields into a new checkout_boxes are of the checkout page | |
foreach($fields as $field) | |
pmprorh_add_registration_field( | |
'donations', | |
$field | |
); | |
//that's it. see the PMPro Register Helper readme for more information and examples. | |
} | |
add_action( 'init', 'my_pmprorh_init' ); | |
// Add the column headings to the Members List | |
function my_pmpro_memberslist_extra_cols_header ( $theusers ) { ?> | |
<th><?php esc_attr_e('General NPSO Gift', 'paid-memberships-pro' ); ?></th> | |
<th><?php esc_attr_e('Rare and Endangered Plant Conservation Fund', 'paid-memberships-pro' ); ?></th> | |
<th><?php esc_attr_e('Leighton Ho Memorial Field Botany Fund', 'paid-memberships-pro' ); ?></th> | |
<?php | |
} | |
add_action( 'pmpro_memberslist_extra_cols_header', 'my_pmpro_memberslist_extra_cols_header', 10 ); | |
// Add the row content for new columns on the Members List | |
function my_pmpro_memberslist_extra_cols_body( $theuser ) { | |
$donation_general_npso_gift = get_user_meta( $theuser->ID, 'donation_general_npso_gift', true ); | |
$donation_rare_and_endangered_plant_fund = get_user_meta( $theuser->ID, 'donation_rare_and_endangered_plant_fund', true ); | |
$donation_leighton_ho_memorial_fund = get_user_meta( $theuser->ID, 'donation_leighton_ho_memorial_fund', true ); | |
?> | |
<td> | |
<?php if ( ! empty( $donation_general_npso_gift ) ) { ?> | |
<?php esc_attr_e( $donation_general_npso_gift ); ?> | |
<?php } else { ?> | |
-- | |
<?php } ?> | |
</td> | |
<td> | |
<?php if ( ! empty( $donation_rare_and_endangered_plant_fund ) ) { ?> | |
<?php esc_attr_e( $donation_rare_and_endangered_plant_fund ); ?> | |
<?php } else { ?> | |
-- | |
<?php } ?> | |
</td> | |
<td> | |
<?php if ( ! empty( $donation_leighton_ho_memorial_fund ) ) { ?> | |
<?php esc_attr_e( $donation_leighton_ho_memorial_fund ); ?> | |
<?php } else { ?> | |
-- | |
<?php } ?> | |
</td> | |
<?php | |
} | |
add_action('pmpro_memberslist_extra_cols_body', 'my_pmpro_memberslist_extra_cols_body'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment