Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/0c4122166e127189e17e4e40fa7b038d to your computer and use it in GitHub Desktop.
Save ipokkel/0c4122166e127189e17e4e40fa7b038d to your computer and use it in GitHub Desktop.
Reorder PMPro checkout fields to Username, First and Last Name, Email and Password. #pmpro #paid-memberships-pro #checkout
<?php
/**
* This recipe moves the checkout fields to appear in the order of
* 1. Username
* 2. First Name and Last Name
* 3. Email
* 4. Password.
*
* Email fields will be moved (always) to before password fields.
* First and Last Name fields will be moved if Add Name to Checkout, or
* Address for Free Levels is active, or if billing address fields are
* on the checkout page.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_reorder_fields_names_email_password_1610434680486() {
global $pmpro_pages, $pmpro_requirebilling;
if ( is_page( $pmpro_pages['checkout'] ) ) {
?>
<script>
jQuery(document).ready(function(){
// move email fields before password
jQuery( '.pmpro_checkout-field-bemail' ).insertBefore( '.pmpro_checkout-field-password' );
jQuery( '.pmpro_checkout-field-bconfirmemail' ).insertAfter( '.pmpro_checkout-field-bemail' );
<?php
// Move first and last name fields if Add Name to Checkout is active.
if ( function_exists( 'pmproan2c_pmpro_checkout_after_password' ) ) {
?>
jQuery( '.pmpro_checkout-field-firstname' ).insertAfter( '.pmpro_checkout-field-username' );
jQuery( '.pmpro_checkout-field-lastname' ).insertAfter( '.pmpro_checkout-field-firstname' );
<?php
}
// If Add Name to Checkout is not active move first and last name fields if the billing address is required
// for the checkout gateway or Address for Free Levels and Offsite gateways is active.
if ( ! function_exists( 'pmproan2c_pmpro_checkout_after_password' ) && ( function_exists( 'pmproaffl_init_include_address_fields_at_checkout' ) || $pmpro_requirebilling ) ) {
?>
jQuery( '.pmpro_checkout-field-bfirstname' ).insertAfter( '.pmpro_checkout-field-username' );
jQuery( '.pmpro_checkout-field-blastname' ).insertAfter( '.pmpro_checkout-field-bfirstname' );
<?php
}
?>
});
</script>
<?php
}
}
add_action( 'wp_footer', 'my_pmpro_reorder_fields_names_email_password_1610434680486' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment