Last active
January 29, 2024 14:34
-
-
Save JarrydLong/57fc9e732f6fc5637e6c41ec3a6d09ce 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 | |
/** | |
* 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( | |
'graduation_year', // input name, will also be used as meta key | |
'textarea', // type of field | |
array( | |
'label' => 'Graduation Year' , | |
'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 Graduation Year field on the membership card. | |
function my_pmpro_add_rh_fields_after_member_card( $pmpro_membership_card_user, $print_sizes, $qr_code, $qr_data ){ | |
$graduation_year = get_user_meta( $pmpro_membership_card_user->ID, 'graduation_year', true ); | |
if( $graduation_year !== "" ){ | |
echo "<p>Graduation Year: ".$graduation_year."</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
This recipe is included in the blog post on "Create a Custom Membership Card for WordPress Users and Members to Print or View Online" at Paid Memberships Pro here: https://www.paidmembershipspro.com/customize-membership-card-wordpress/