Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Last active October 11, 2018 05:47
Show Gist options
  • Save pbrocks/9ac6fc037825c6f99dee8c066e3145de to your computer and use it in GitHub Desktop.
Save pbrocks/9ac6fc037825c6f99dee8c066e3145de to your computer and use it in GitHub Desktop.
Use jQuery to move a Register Helper field on the Checkout page.
jQuery(document).ready(function($){
$('#pmpro_county_div').appendTo($('#bzipcode').parent());
$('#pmpro_checkout_box-checkout_boxes').css('display','none');
});
<?php
/**
* Plugin Name: PMPro Customizations
* Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/
* Description: Customizations for positioning Register Helper field. Add this php file and .js file to Customizations plugin's folder.
* Version: .1
* Author: Paid Memberships Pro
* Author URI: https://www.paidmembershipspro.com
*/
function add_counties_field_to_checkout() {
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return;
}
$pmpro_counties = create_county_fields_for_profile();
$fields = array();
$fields[] = new PMProRH_Field(
'pmpro_county', 'select', array(
'label' => 'County',
'profile' => true,
'location' => 'after_username',
'required' => false,
'options' => array_merge(
array(
'' => '- choose one -',
),
$pmpro_counties
),
)
);
// add the fields into a new checkout_boxes are of the checkout page
foreach ( $fields as $field ) {
pmprorh_add_registration_field( 'checkout_boxes', $field );
}
}
add_action( 'init', 'add_counties_field_to_checkout' );
function create_county_fields_for_profile() {
$counties = array(
'alamance' => 'Alamance',
'alexander' => 'Alexander',
'alleghany' => 'Alleghany',
'anson' => 'Anson',
'cabarrus' => 'Cabarrus',
'caswell' => 'Caswell',
'catawba' => 'Catawba',
'chatham' => 'Chatham',
'davidson' => 'Davidson',
'davie' => 'Davie',
'forsyth' => 'Forsyth',
'gaston' => 'Gaston',
'guilford' => 'Guilford',
'iredell' => 'Iredell',
'lincoln' => 'Lincoln',
'mecklenburg' => 'Mecklenburg',
'montgomery' => 'Montgomery',
'moore' => 'Moore',
'randolph' => 'Randolph',
'richmond' => 'Richmond',
'rockingham' => 'Rockingham',
'rowan' => 'Rowan',
'stanly' => 'Stanly',
'stokes' => 'Stokes',
'surry' => 'Surry',
'union' => 'Union',
'wilkes' => 'Wilkes',
'yadkin' => 'Yadkin',
);
return $counties;
}
add_action( 'wp_enqueue_scripts', 'add_jquery_to_move_something' );
function add_jquery_to_move_something() {
wp_enqueue_script( 'move-something', plugins_url( 'move-something.js', __FILE__ ), array( 'jquery' ), '1.2' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment