Last active
August 24, 2023 12:20
-
-
Save kimwhite/9ae54f84cbfa569df192d6894f7ed8fe to your computer and use it in GitHub Desktop.
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 | |
/** | |
* This recipe will add additional fees and pricing | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
//we have to put everything in a function called on init, so we are sure Register Helper is loaded | |
function my_pmprorh_init() | |
{ | |
//don't break if Register Helper is not loaded | |
if(!function_exists( 'pmprorh_add_registration_field' )) { | |
return false; | |
} | |
$fields[] = new PMProRH_Field( | |
'addon_options', // input field name, used as meta key | |
'checkbox_grouped', // field type | |
array( | |
'label' => 'Choose your selection', | |
'options' => array( // display the different options, no need for a "blank" option | |
'add_on_a' => 'I would like to receive paper copies of JLS: US $20', | |
'add_on_b' => 'I would like to receive paper copies of ijCSCL: US $20', | |
), | |
'profile' => true, | |
'memberslistcsv' => true, | |
'addmember' => true, | |
'required' => false, | |
) | |
); | |
//add the fields into a new checkout_boxes are of the checkout page | |
foreach($fields as $field) | |
pmprorh_add_registration_field( | |
'checkout_boxes', // location on checkout page | |
$field // PMProRH_Field object | |
); | |
//that's it. see the PMPro Register Helper readme for more information and examples. | |
} | |
add_action( 'init', 'my_pmprorh_init' ); | |
function my_pmpro_checkout_level($level) | |
{ | |
$addon_checkboxes = !empty( $_REQUEST['addon_options'] ) ? $_REQUEST['addon_options'] : ''; | |
if ( ! is_array( $addon_checkboxes ) ) { | |
return $level; | |
} | |
foreach( $addon_checkboxes as $options ) { | |
switch( $options ) { | |
case "add_on_a": | |
$level->initial_payment = $level->initial_payment + 20; //to update the initial payment. | |
//$level->billing_amount = $level->billing_amount + 49; //to update recurring payments too | |
break; | |
case "add_on_b": | |
$level->initial_payment = $level->initial_payment + 20; //to update the initial payment. | |
//$level->billing_amount = $level->billing_amount + 99; //to update recurring payments too | |
break; | |
} | |
} | |
return $level; | |
} | |
add_filter( 'pmpro_checkout_level', 'my_pmpro_checkout_level' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment