Last active
August 29, 2023 09:07
-
-
Save kimwhite/8f6d89b24ca1ad12e65823893d86f7d7 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 will allow you to charge additional extras on the user's fee. | |
* | |
* 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; | |
} | |
//define the fields | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'signupfee', // input name, will also be used as meta key | |
'checkbox', // type of field | |
array( | |
'label' => 'Signup Fee $30', // custom field label | |
'hint' => 'I understand there is a new members fee', | |
'levels' => 1, | |
'required' => true, | |
) | |
); | |
//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) | |
{ | |
if ( ! empty( $_REQUEST['signupfee'] ) ) { | |
$level->initial_payment = $level->initial_payment + 30; //to update the initial payment. | |
// $level->billing_amount = $level->billing_amount + 175; //to update recurring payments too | |
} | |
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