Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save greathmaster/343ebd0a3c827fd4adb5d6361d5adc5c to your computer and use it in GitHub Desktop.
Save greathmaster/343ebd0a3c827fd4adb5d6361d5adc5c to your computer and use it in GitHub Desktop.
Donate to specific categories or causes using PMPro Register Helper.
<?php
/*Donate to specific categories or causes using PMPro Register Helper. This is different and independent from the PMPro Donations Add On.*/
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");
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' => 'admin_only'
)
);
$fields[] = new PMProRH_Field(
'donation_rare_and_endangered_plant_fund',
'text',
array(
'label' => 'Rare and Endangered Plant Conservation Fund',
'size' => 7,
'profile' => 'admin_only'
)
);
$fields[] = new PMProRH_Field(
'donation_leighton_ho_memorial_fund',
'text',
array(
'label' => 'Leighton Ho Memorial Field Botany Fund',
'size' => 7,
'profile' => 'admin_only'
)
);
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment