Last active
May 13, 2025 13:23
-
-
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
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 | |
/** | |
* 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_form_field-bemail' ).insertBefore( '.pmpro_form_field-password' ); | |
jQuery( '.pmpro_form_field-bconfirmemail' ).insertAfter( '.pmpro_form_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_form_field-firstname' ).insertAfter( '.pmpro_form_field-username' ); | |
jQuery( '.pmpro_form_field-lastname' ).insertAfter( '.pmpro_form_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_form_field-bfirstname' ).insertAfter( '.pmpro_form_field-username' ); | |
jQuery( '.pmpro_form_field-blastname' ).insertAfter( '.pmpro_form_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