Skip to content

Instantly share code, notes, and snippets.

@MaximilianoRicoTabo
Last active February 21, 2024 20:53
Show Gist options
  • Save MaximilianoRicoTabo/abf9e67db3ff92909d117d68fdec9b9b to your computer and use it in GitHub Desktop.
Save MaximilianoRicoTabo/abf9e67db3ff92909d117d68fdec9b9b to your computer and use it in GitHub Desktop.
show billing fields from last order in the admin user profile
<?php
/**
* Sync billing fields from last order to match recipe from this article below
* https://www.paidmembershipspro.com/display-the-members-billing-address-fields-on-the-edit-user-page-for-admin-only/
*
* link: TBD
*
* 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 pmpro_display_billing_fields ( $user ) {
global $wpdb;
//get last user invoice
$last_invoice = $wpdb->get_row("SELECT * FROM wp_pmpro_membership_orders WHERE user_id = $user->ID ORDER BY id DESC LIMIT 1");
?>
<h3>Billing Fields</h3>
<table class="form-table">
<tr>
<th><label for="billing_name">Billing Name</label></th>
<td><?php echo $last_invoice->billing_name ?></td>
</tr>
<tr>
<th><label for="billing_street">Address</label></th>
<td><?php echo $last_invoice->billing_street; ?></td>
</tr>
<tr>
<th><label for="billing_city">City</label></th>
<td><?php echo $last_invoice->billing_city; ?></td>
</tr>
<tr>
<th><label for="billing_state">State</label></th>
<td><?php echo $last_invoice->billing_state; ?></td>
</tr>
<tr>
<th><label for="billing_country">Country</label></th>
<td><?php echo $last_invoice->billing_country; ?></td>
</tr>
<tr>
<th><label for="billing_zip">Zip</label></th>
<td><?php echo $last_invoice->billing_zip; ?></td>
</tr>
<tr>
<th><label for="billing_phone">Phone</label></th>
<td><?php echo $last_invoice->billing_phone; ?></td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'pmpro_display_billing_fields' ); // editing your own profile
add_action( 'edit_user_profile', 'pmpro_display_billing_fields' ); // editing another user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment