Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created February 12, 2018 07:46
Show Gist options
  • Save andrewlimaza/173d503f8557f1ff0d92f8b433b605cc to your computer and use it in GitHub Desktop.
Save andrewlimaza/173d503f8557f1ff0d92f8b433b605cc to your computer and use it in GitHub Desktop.
Change Pricing Based On Level Paid Memberships Pro
<?php
/**
* Change the pricing of a membership level based on the level of user.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_charge_discount_for_level( $level ) {
// If the user does not have a level, bail.
if( ! pmpro_hasMembershipLevel() ){
return $level;
}
if( pmpro_hasMembershipLevel( '1' ) ) { // adjust current level to check against.
$level->initial_payment = ( $level->initial_payment/2 );
}
return $level;
}
add_filter( 'pmpro_checkout_level', 'my_charge_discount_for_level' );
//change price cost for level if we have a level.
function my_change_price_text_for_level( $cost, $level ) {
if( pmpro_hasMembershipLevel( '1' ) ) { // change level ID to level that the user must have in order to change pricing.
if( '2' == $level->id ) { // change level ID for level to change cost on.
$cost = str_replace( '250.00', '125.00', $cost );
}
}
return $cost;
}
add_filter( 'pmpro_level_cost_text', 'my_change_price_text_for_level', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment