Created
February 21, 2018 19:49
-
-
Save kimcoleman/49b95ca56b860e73ed7280cac71cce80 to your computer and use it in GitHub Desktop.
Custom Register Helper fields for Irishhealer thread on price-adjusting fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom Register Helper fields for Irishhealer thread on price-adjusting fields. | |
*/ | |
function irishhealer_adjust_price_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( | |
'additional_adults', | |
'text', | |
array( | |
'label' => 'Number of Adults (+30€)', | |
'levels' => array( '3' ), | |
'memberslistcsv' => true, | |
'profile' => 'admin_only', | |
) ); | |
$fields[] = new PMProRH_Field( | |
'additional_juniors', | |
'text', | |
array( | |
'label' => 'Number of Juniors (+10€)', | |
'levels' => array( '3' ), | |
'memberslistcsv' => true, | |
'profile' => 'admin_only', | |
) ); | |
// Add the fields into a new checkout_boxes are of the checkout page. | |
pmprorh_add_checkout_box( 'family', 'Family Details' ); | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( | |
'family', | |
$field | |
); | |
} | |
} | |
add_action( 'init', 'irishhealer_adjust_price_pmprorh_init' ); | |
/** | |
* If a user added adults or juniors options, then adjust the price. | |
* | |
* @param object $level The level bobject being purchased at checkout. | |
*/ | |
function irishhealer_adjust_price_pmpro_checkout_level( $level ) { | |
if ( ! empty( $_REQUEST['additional_adults'] ) ) { | |
$additional_adults = $_REQUEST['additional_adults']; | |
$level->initial_payment = $level->initial_payment + ( intval( $additional_adults ) * 30 ); | |
$level->billing_amount = $level->billing_amount + ( intval( $additional_adults ) * 30 ); | |
} | |
if ( ! empty( $_REQUEST['additional_juniors'] ) ) { | |
$additional_juniors = $_REQUEST['additional_juniors']; | |
$level->initial_payment = $level->initial_payment + ( intval( $additional_juniors ) * 10 ); | |
$level->billing_amount = $level->billing_amount + ( intval( $additional_juniors ) * 10 ); | |
} | |
return $level; | |
} | |
add_filter( 'pmpro_checkout_level', 'irishhealer_adjust_price_pmpro_checkout_level' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment