Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. greathmaster created this gist Feb 6, 2018.
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    /*
    Code demo on using pmprosm_children_fields() and pmprosm_after_child_created() hooks to add additional fields to checkout child account creation.
    Adds shipping fields to child accounts at checkout. Use PMPro Shipping Address on Membership Checkout to view
    */

    function pmprosm_additional_child_fields($i, $seats)
    {?><label>Shipping Address 1</label><input type="text" name="add_child_saddress1[]" value="" size="20" /><label>Shipping Address 2</label><input type="text" name="add_child_saddress2[]" value="" size="20" /><label>City</label><input type="text" name="add_child_scity[]" value="" size="20" /><label>State</label><input type="text" name="add_child_sstate[]" value="" size="20" /><label>Postal Code</label><input type="text" name="add_child_szipcode[]" value="" size="20" /><?php
    }

    add_action('pmprosm_children_fields', 'pmprosm_additional_child_fields', 10, 2);

    function pmprosm_save_additional_child_fields($child_user_id, $user_id, $i)
    {

    if(!empty($_REQUEST['add_sub_accounts_first_name']))
    $child_first_name = $_REQUEST['add_sub_accounts_first_name'];
    else
    $child_first_name = '';

    if(!empty($_REQUEST['add_sub_accounts_last_name']))
    $child_last_name = $_REQUEST['add_sub_accounts_last_name'];
    else
    $child_last_name = '';

    if(!empty($_REQUEST['add_child_saddress1']))
    $child_saddress1 = $_REQUEST['add_child_saddress1'];
    else
    $child_saddress1 = '';

    if(!empty($_REQUEST['add_child_saddress2']))
    $child_saddress2 = $_REQUEST['add_child_saddress2'];
    else
    $child_saddress2 = '';

    if(!empty($_REQUEST['add_child_scity']))
    $child_scity = $_REQUEST['add_child_scity'];
    else
    $child_scity = '';

    if(!empty($_REQUEST['add_child_sstate']))
    $child_sstate = $_REQUEST['add_child_sstate'];
    else
    $child_sstate = '';

    if(!empty($_REQUEST['add_child_szipcode']))
    $child_szipcode = $_REQUEST['add_child_szipcode'];
    else
    $child_szipcode = '';

    if(!empty($child_saddress1))
    {
    update_user_meta($child_user_id, "pmpro_sfirstname", $child_first_name[$i]);
    update_user_meta($child_user_id, "pmpro_slastname", $child_last_name[$i]);
    update_user_meta($child_user_id, "pmpro_saddress1", $child_saddress1[$i]);
    update_user_meta($child_user_id, "pmpro_saddress2", $child_saddress2[$i]);
    update_user_meta($child_user_id, "pmpro_scity", $child_scity[$i]);
    update_user_meta($child_user_id, "pmpro_sstate", $child_sstate[$i]);
    update_user_meta($child_user_id, "pmpro_szipcode", $child_szipcode[$i]);
    }
    }

    add_action('pmprosm_after_child_created', 'pmprosm_save_additional_child_fields', 10, 3);

    function pmpro_sponsored_member_settings()
    {
    global $pmprosm_sponsored_account_levels;

    $pmprosm_sponsored_account_levels = array(
    7 => array(
    'main_level_id' => 7,
    'sponsored_level_id' => array(8),
    // 'seats' => 20,
    'seat_cost' => 10,
    'max_seats' => 5,
    'min_seats' => 2,
    'sponsored_accounts_at_checkout' => true,
    'children_get_name' => true,
    'children_hide_username' => false,
    'children_hide_email' => false,
    'children_hide_password' => false,
    ),
    );

    }

    add_action('init', 'pmpro_sponsored_member_settings');