Created
March 28, 2023 09:44
-
-
Save ipokkel/a3a02a2196c1163c254b2d584a0023ff to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Example of changing the group (location ) to add a user field to. | |
* | |
* "$where" locations available on the checkout page are: | |
* - after_pricing_fields | |
* - after_username | |
* - after_password | |
* - after_email | |
* - checkout_boxes | |
* - after_billing_fields | |
* - after_tos_fields | |
* - after_captcha | |
* - before_submit_button | |
* - just_profile (make sure you set the profile attr of the field to true or admins) | |
* | |
* Where locations are also the Group names for groups created when adding a group in Memberships > Settings > User Fields. | |
* For example, if you created a group named "Pets" the $where location would be "Pets". | |
* | |
* This function hooks into the "pmpro_add_user_field_where" filter. | |
* | |
* @link https://www.paidmembershipspro.com/hook/pmpro_add_user_field_where/ | |
* @since 2.9.3 | |
* @param string $where The name of the group to add the field to. | |
* @param PMProField $field The field being added. | |
* | |
* 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_change_user_field_where_example( $where, $field ) { | |
// Match field name and set the location to add the field to. | |
if ( 'field_name' === $field->name && 'after_pricing_fields' !== $where ) { | |
// Let's change the location to add the field to. | |
$where = 'after_pricing_fields'; // Change the location to add the field to here. | |
} | |
return $where; | |
} | |
add_filter( 'pmpro_add_user_field_where', 'my_pmpro_change_user_field_where_example', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment