Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active March 22, 2022 13:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/7a0dcf8478afafb0ce7126ac70cdb667 to your computer and use it in GitHub Desktop.
Save andrewlimaza/7a0dcf8478afafb0ce7126ac70cdb667 to your computer and use it in GitHub Desktop.
Adjust pricing for membership level according to selection of Custom Fields in Paid Memberships Pro.
<?php
/**
* This will allow you to charge additional extras on the user's monthly membership fee.
* Copy the code below into your PMPro Customizations Plugin - 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(
'expert', // input name, will also be used as meta key
'checkbox', // type of field
array(
'label' => 'Add $175/mo', // custom field label
'levels' => array(1)
)
);
$fields[] = new PMProRH_Field(
'research', // input name, will also be used as meta key
'checkbox', // type of field
array(
'label' => 'Add $95/mo', // custom field label
'levels' => array(1)
)
);
$fields[] = new PMProRH_Field(
'complete_upgrade', // input name, will also be used as meta key
'checkbox', // type of field
array(
'label' => 'Add $270/mo', // custom field label
'levels' => array(1)
)
);
$fields[] = new PMProRH_Field(
'expert_2', // input name, will also be used as meta key
'checkbox', // type of field
array(
'label' => 'Add $200/mo', // custom field label
'levels' => array(2)
)
);
$fields[] = new PMProRH_Field(
'research_2', // input name, will also be used as meta key
'checkbox', // type of field
array(
'label' => 'Add $145/mo', // custom field label
'levels' => array(2)
)
);
$fields[] = new PMProRH_Field(
'complete_upgrade_2', // input name, will also be used as meta key
'checkbox', // type of field
array(
'label' => 'Add $350/mo', // custom field label
'levels' => array(2)
)
);
//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['expert'] ) ) {
// $level->initial_payment = $level->initial_payment + 175; //to update the initial payment.
$level->billing_amount = $level->billing_amount + 175; //to update recurring payments too
}
if ( ! empty( $_REQUEST['research'] ) ) {
$level->billing_amount = $level->billing_amount + 95; //to update recurring payments too
}
if ( ! empty( $_REQUEST['complete_upgrade'] ) ) {
$level->billing_amount = $level->billing_amount + 270; //to update recurring payments too
}
if ( ! empty( $_REQUEST['expert_2'] ) ) {
$level->billing_amount = $level->billing_amount + 200; //to update recurring payments too
}
if ( ! empty( $_REQUEST['research_2'] ) ) {
$level->billing_amount = $level->billing_amount + 145; //to update recurring payments too
}
if ( ! empty( $_REQUEST['complete_upgrade_2'] ) ) {
$level->billing_amount = $level->billing_amount + 350; //to update recurring payments too
}
return $level;
}
add_filter( "pmpro_checkout_level", "my_pmpro_checkout_level" );
@sensemonster
Copy link

Hi, doesn't this need a add_filter( "pmpro_checkout_level", "my_pmpro_checkout_level" ); at the end ?

@andrewlimaza
Copy link
Author

Thanks @sensemonster, I have updated the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment