Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/ff44b84484700d44411b8bc5d2dfa58e to your computer and use it in GitHub Desktop.
Save ipokkel/ff44b84484700d44411b8bc5d2dfa58e to your computer and use it in GitHub Desktop.
Custom Fields for Register Helper with JQuery Datepicker
<?php
/*
Plugin Name: PMPro Customizations
Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Customizations for my Paid Memberships Pro Setup
Version: .1
Author: Paid Memberships Pro
Author URI: https://www.paidmembershipspro.com
*/
//Now start placing your customization code below this line
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
}
$fields[] = new PMProRH_Field(
'insured',
'radio',
array(
'label' => 'Insured?',
'options' => array(
'yes' => 'Yes',
'no' => 'No',
),
'required' => true,
'profile' => true,
// 'memberslistcsv' => true, /* Uncomment to include in Memberlist CSV */
// "addmember" => true, /* Uncomment if using the Admin Add Member plugin */
)
);
// "depends" => array( array( 'id' => 'newsletter_other', 'value' => '1' ) ),
$fields[] = new PMProRH_Field(
'insuretype',
'select',
array(
'depends' => array(array( 'id' => 'insured', 'value' => 'yes' ) ),
'label' => 'If yes, insurance type?',
'options' => array(
'medicaid' => 'Medicaid',
'medicare'=> 'Medicare',
'commercial'=> 'Commercial',
),
'required' => true,
'profile' => true,
// 'memberslistcsv' => true, /* Uncomment to include in Memberlist CSV */
// "addmember" => true, /* Uncomment if using the Admin Add Member plugin */
)
);
$fields[] = new PMProRH_Field(
'hhm',
'text',
array(
'label' => 'House Hold Members',
'size' => 10,
'required' => true,
'profile' => true,
// 'memberslistcsv' => true, /* Uncomment to include in Memberlist CSV */
// "addmember" => true, /* Uncomment if using the Admin Add Member plugin */
)
);
$fields[] = new PMProRH_Field(
'dob', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'Date Of Birth', // custom field label
'class' => 'my-datepicker', // datepicker class
'profile' => true, // show in user profile
'required' => true, // make this field required
// 'addmember' => true, // Uncomment to display in Add Member
// 'memberslistcsv' => true, // Uncomment to Include in Member List CSV Export
)
);
$fields[] = new PMProRH_Field(
'ssn',
'text',
array(
'label' => 'SSN',
'required' => true,
'profile' => true,
// 'memberslistcsv' => true, /* Uncomment to include in Memberlist CSV */
// "addmember" => true, /* Uncomment if using the Admin Add Member plugin */
)
);
// Source (multiselect) [Renewal, Radio, Newspaper, Television, Billboard, Other]
$fields[] = new PMProRH_Field(
'source',
'multiselect',
array(
'label' => 'Source',
'options' => array(
'renewal' => 'Renewal',
'radio'=> 'Radio',
'newspaper'=> 'Newspaper',
'television' => 'Television',
'billboard'=> 'Billboard',
'other'=> 'Other',
),
'required' => true,
'profile' => true,
// 'memberslistcsv' => true, /* Uncomment to include in Memberlist CSV */
// "addmember" => true, /* Uncomment if using the Admin Add Member plugin */
)
);
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
'checkout_boxes', // location on checkout page
$field // PMProRH_Field object
);
//that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmprorh_init' );
/**
* Load content for specific pages, checkout or confirmation page
*/
function load_my_script_for_pmpro() {
global $pmpro_pages;
if ( is_page( $pmpro_pages['checkout'] ) || is_page( $pmpro_pages['confirmation'] ) || is_page( $pmpro_pages['account'] ) || is_page( $pmpro_pages['billing'] ) || is_page( $pmpro_pages['cancel'] ) || is_page( $pmpro_pages['invoice'] ) || is_page( $pmpro_pages['levels'] ) || is_page( $pmpro_pages['popup-cvv'] ) || defined( 'IS_PROFILE_PAGE' ) ) {
?>
<script>
jQuery(document).ready(function($) {
$( '.my-datepicker' ).datepicker( {
dateFormat: 'yy-mm-dd',
showButtonPanel: true,
changeMonth: true,
changeYear: true
});
});
</script>
<style>
/* Customize the style and layout for the Jquery datepicker here */
#ui-datepicker-div {
background-color: #fff;
/* border: 1px solid #333; */
}
</style>
<?php
}
}
add_action( 'wp_head', 'load_my_script_for_pmpro' );
if( defined( 'IS_PROFILE_PAGE' ) )
add_action( 'admin_head', 'load_my_script_for_pmpro' );
function my_enqueue_scripts()
{
// tell WordPress to load the JQuery Datepicker, the ui-core depency will automatically be loaded,
wp_enqueue_script('jquery-ui-datepicker');
}
add_action('wp_enqueue_scripts', 'my_enqueue_scripts');
add_action('admin_enqueue_scripts', 'my_enqueue_scripts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment