Forked from dparker1005/my_pmpro_move_billing_fields.php
Last active
May 2, 2025 08:55
-
-
Save davidmutero/39eff55b0951286b7462a53ede953bfa to your computer and use it in GitHub Desktop.
Move a User Field Group Below the Billing Address on PMPro 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 | |
/** | |
* Move a specific user field group (e.g. Company Info) below the Billing Address on PMPro Checkout. | |
* | |
* This uses JavaScript to reposition any fieldset by targeting its ID. | |
* Update the `$fieldset_id` value to match the fieldset you want to move. | |
* | |
* 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. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function move_user_fieldset_after_billing_address() { | |
if ( is_page( pmpro_getOption( 'checkout' ) ) ) { | |
$fieldset_id = 'pmpro_form_fieldset-user-fieldset'; // Update to your fieldset ID | |
?> | |
<script> | |
document.addEventListener('DOMContentLoaded', function () { | |
const userFieldset = document.querySelector('#<?php echo esc_js( $fieldset_id ); ?>'); | |
const billingFields = document.querySelector('#pmpro_billing_address_fields'); | |
if (userFieldset && billingFields) { | |
billingFields.parentNode.insertBefore(userFieldset, billingFields.nextSibling); | |
} | |
}); | |
</script> | |
<?php | |
} | |
} | |
add_action( 'wp_footer', 'move_user_fieldset_after_billing_address' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment