Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelbeil/69c5acf469ae5dc4d46d0f080bb8e7cb to your computer and use it in GitHub Desktop.
Save michaelbeil/69c5acf469ae5dc4d46d0f080bb8e7cb to your computer and use it in GitHub Desktop.
PMPro Sponsored Members Example Variable seat pricing
<?php // do not copy this line.
/**
* Sponsored Members setup with child seat costs at checkout.
* SPONSOR SEAT + 4 seats @ 1120 each
* + 5 to 10 @ 275 each
*
* 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/
*/
global $pmprosm_sponsored_account_levels;
$pmprosm_sponsored_account_levels = array(
4 => array( //Sponsor Level
'main_level_id' => 4, // Sponsor Level AGAIN
'sponsored_level_id' => 5, // Child Level
'seat_cost' => 1120, // cost per seat 4 and under
'min_seats' => 4,
'max_seats' => 10,
'seat_cost_text' => '<br />(1120 each) and then for child seats 5 to 10 @ 275',
)
);
/**
* Remove Sponsored Members Pricing update and use our own.
*/
function my_init_override_sponsored_members_pricing_update() {
remove_filter( 'pmpro_checkout_level', 'pmprosm_pmpro_checkout_levels' );
add_filter( 'pmpro_checkout_level', 'my_custom_pmpro_seat_pricing' );
}
add_action( 'init', 'my_init_override_sponsored_members_pricing_update' );
/**
* My custom pricing.
*/
function my_custom_pmpro_seat_pricing( $level ) {
// Only concerned about level 1
if ( $level->id != 4 ) { // Change to Your Sponsor Level ID
return $level;
}
// get seats from submit
if ( isset( $_REQUEST['seats'] ) )
$seats = intval($_REQUEST['seats']);
else
$seats = "";
switch ( $seats ) {
case $seats < 5:
$level->initial_payment = $level->initial_payment + ($seats * 1120);
$level->billing_amount = $level->billing_amount + ($seats * 1120);
break;
case $seats <= 11:
$level->initial_payment = $level->initial_payment + ($seats * 275);
$level->billing_amount = $level->billing_amount + ($seats * 275);
break;
}
return $level;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment