strangerstudios / pmpro-register-helper

A robust plugin to collect additional fields for WordPress users. Fields can be collected at membership checkout, on the user's profile or for administrative view-only.
https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
29 stars 41 forks source link

Add field location at pmpro_checkout_after_tos_fields action hook #238

Open ipokkel opened 2 years ago

ipokkel commented 2 years ago

Is your feature request related to a problem? Please describe. There is no current location for RH fields at the relatively new pmpro_checkout_after_tos_fields action hook. We should consider adding this as a location for Register Helper.

Describe the solution you'd like Have a after_tos_fields location for Register Helper to add registration fields to, e.g. pmprorh_add_registration_field( 'after_tos_fields', $field );

Describe alternatives you've considered Add the location for Register Helper with custom code in a customization plugin.

if ( ! function_exists( 'pmprorh_pmpro_checkout_after_tos_fields' ) ) {
    function pmprorh_pmpro_checkout_after_tos_fields() {
        global $pmprorh_registration_fields;

        if ( ! empty( $pmprorh_registration_fields['after_tos_fields'] ) ) {
            foreach ( $pmprorh_registration_fields['after_tos_fields'] as $field ) {
                if ( is_a( $field, 'PMProRH_Field' ) && pmprorh_checkFieldForLevel( $field ) && ( ! isset( $field->profile ) || $field->profile !== 'only' && $field->profile !== 'only_admin' ) ) {
                    $field->displayAtCheckout();
                }
            }
        }
    }
    add_action( 'pmpro_checkout_after_tos_fields', 'pmprorh_pmpro_checkout_after_tos_fields' );
}

https://gist.github.com/ipokkel/b127705f8a91dcb5920f3cb8da920fca

Additional context

Adding this location allows developers to add a registration field after the TOS fields and before the captcha location.

Ticket (moderators only): #416912