Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 19.95 each
* + 5 to 19 @ 17.95
* + 20 to 39 @ $15.95
* + 40 to 79 @ 14.95
*
* 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(s)
'seat_cost' => 19.95, //cost per seat 4 and under
'min_seats' => 4,
'max_seats' => 79,
'seat_cost_text' => '<br />(19.95 each) and then for child seats 5 to 20 @ 17.95 then child seats <br /> 21-40 @ $15.95 and seats 41-80 @ 14.95',
)
);
/**
* 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 * 19.95);
$level->billing_amount = $level->billing_amount + ($seats * 19.95);
break;
case $seats <= 19:
$level->initial_payment = $level->initial_payment + ($seats * 17.95) - 2;
$level->billing_amount = $level->billing_amount + ($seats * 17.95) - 2;
break;
case $seats <= 39:
$level->initial_payment = $level->initial_payment + ($seats * 15.95) - 4;
$level->billing_amount = $level->billing_amount + ($seats * 15.95) - 4;
break;
case $seats <= 79:
$level->initial_payment = $level->initial_payment + ($seats * 14.95) - 5;
$level->billing_amount = $level->billing_amount + ($seats * 14.95) - 5;
break;
}
return $level;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment