Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/3859242ccbe183d536ee54a6870b6308 to your computer and use it in GitHub Desktop.
Save kimcoleman/3859242ccbe183d536ee54a6870b6308 to your computer and use it in GitHub Desktop.
PMPro Register Helper Customizations for donteatthat Thread
<?php
/**
* Custom Register Helper fields for donteatthat thread on price-adjusting fields.
*/
function donteatthat_pmprorh_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
$fields = array();
$fields[] = new PMProRH_Field(
'company_type',
'radio',
array(
'label' => 'Company Type',
'levels' => 1,
'memberslistcsv' => true,
'options' => array(
'B1' => 'B1 (+ $10/mo.)',
'B2' => 'B2 (+ $20/mo.)',
'B3' => 'B3 (+ $30/mo.)',
'B4' => 'B4 (+ $40/mo.)',
'B5' => 'B5 (+ $50/mo.)',
),
'profile' => 'admin_only',
'readonly' => 'true',
) );
$fields[] = new PMProRH_Field(
'guidance',
'radio',
array(
'label' => 'Guidance',
'levels' => 1,
'memberslistcsv' => true,
'options' => array(
'G1' => 'G1 (+ $80/mo.)',
'G2' => 'G2 (+ $90/mo.)',
),
'profile' => 'admin_only',
'readonly' => 'true',
) );
// Add the fields in the appropriate spot based on the page.
foreach ( $fields as $field ) {
pmprorh_add_registration_field( 'checkout_boxes', $field );
}
}
add_action( 'init', 'donteatthat_pmprorh_init' );
function donteatthat_pmpro_checkout_level( $level ) {
// Get the user selections for Company Type and Guidance.
if ( ! empty( $_REQUEST['company_type'] ) ) {
$company_type = $_REQUEST['company_type'];
}
if ( ! empty( $_REQUEST['guidance'] ) ) {
$guidance = $_REQUEST['guidance'];
}
// Modify price based on Company Type selected.
if ( ! empty( $company_type ) ) {
if ( $company_type === 'B1' ) {
// Increase price by $10 per month.
$level->initial_payment = $level->initial_payment + 10;
$level->billing_amount = $level->billing_amount + 10;
} elseif ( $company_type === 'B2' ) {
// Increase price by $20 per month.
$level->initial_payment = $level->initial_payment + 20;
$level->billing_amount = $level->billing_amount + 20;
} elseif ( $company_type === 'B3' ) {
// Increase price by $30 per month.
$level->initial_payment = $level->initial_payment + 30;
$level->billing_amount = $level->billing_amount + 30;
} elseif ( $company_type === 'B4' ) {
// Increase price by $40 per month.
$level->initial_payment = $level->initial_payment + 40;
$level->billing_amount = $level->billing_amount + 40;
} elseif ( $company_type === 'B5' ) {
// Increase price by $50 per month.
$level->initial_payment = $level->initial_payment + 50;
$level->billing_amount = $level->billing_amount + 50;
}
}
// Modify price based on Guidance selected.
if ( ! empty( $guidance ) ) {
if ( $guidance === 'G1' ) {
// Increase price by $80 per month.
$level->initial_payment = $level->initial_payment + 80;
$level->billing_amount = $level->billing_amount + 80;
} elseif ( $guidance === 'G2' ) {
// Increase price by $90 per month.
$level->initial_payment = $level->initial_payment + 90;
$level->billing_amount = $level->billing_amount + 90;
}
}
return $level;
}
add_filter( 'pmpro_checkout_level', 'donteatthat_pmpro_checkout_level' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment