Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimwhite/45dd13e5aa4ad59030005a4febddb91c to your computer and use it in GitHub Desktop.
Save kimwhite/45dd13e5aa4ad59030005a4febddb91c to your computer and use it in GitHub Desktop.
<?php
/**
* This recipe will create a custom field using the Register Helper Add-on, and display the
* respective field on the membership card.
*
* 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/
*/
//Create the custom field
function my_pmprorh_init(){
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
}
$fields[] = new PMProRH_Field(
'partner_first_name', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'partner_first_name' ,
'profile' => true,
'required' => true
)
);
$fields[] = new PMProRH_Field(
'partner_last_name', // input name, will also be used as meta key
'text', // type of field
array(
'label' => 'partner_last_name' ,
'profile' => true,
'required' => true
)
);
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
'checkout_boxes', // location on checkout page
$field // PMProRH_Field object
);
//that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmprorh_init' );
//Now display the Custom fields on the membership card.
function my_pmpro_add_rh_fields_after_member_card( $pmpro_membership_card_user, $print_sizes, $qr_code, $qr_data ){
$partner_first_name = get_user_meta( $pmpro_membership_card_user->ID, 'partner_first_name', true );
$partner_last_name = get_user_meta( $pmpro_membership_card_user->ID, 'partner_last_name', true );
if( $partner_first_name !== "" ){
echo "<p>Partner: ".$partner_first_name.' ' .$partner_last_name."</p>";
//Wrapping content in <p> tags will help with consistent spacing
}
}
add_action( 'pmpro_membership_card_after_card', 'my_pmpro_add_rh_fields_after_member_card', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment