Forked from ipokkel/move-pmpro-checkout-fields-js.php
Created
January 2, 2025 16:21
-
-
Save kimwhite/878529007aacb043fd3fe2503d574a77 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Move PMPro checkout fields using jQuery. | |
* | |
* 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_move_pmpro_checkout_fields_js() { | |
// Is PMPro active and are we on the checkout page? | |
if ( ! function_exists( 'pmpro_is_checkout' ) || ! pmpro_is_checkout() ) { | |
return; | |
} | |
?> | |
<script> | |
jQuery(document).ready(function($) { | |
// Get the fields | |
var userName = $('#pmpro_user_fields .pmpro_form_field-username'); | |
var firstName = $('#pmpro_user_fields .pmpro_form_field-firstname'); | |
var lastName = $('#pmpro_user_fields .pmpro_form_field-lastname'); | |
var bEmail = $('#pmpro_user_fields .pmpro_form_field-bemail'); | |
// bail if any of these fields do not exist | |
if ( ! userName.length || ! firstName.length || ! lastName.length || ! bEmail.length ) { | |
return; | |
} | |
// move the fields | |
firstName.insertAfter(userName); | |
lastName.insertAfter(firstName); | |
bEmail.insertAfter(lastName); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'my_move_pmpro_checkout_fields_js' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment