Last active
January 9, 2024 20:40
-
-
Save mburnette/d7d95516c670a03673d4f2fb82b0555a to your computer and use it in GitHub Desktop.
[Billing names on WC Memberships admin page] Add billing first and last name to WooCommerce Memberships admin page #WooCommerceMemberships
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 // only copy this line if needed | |
/** | |
* Add billing first and last name to WooCommerce Memberships admin page | |
*/ | |
function sv_wc_memberships_add_billing_name_columns( $columns ) { | |
$columns['wcmember_first_name'] = __( 'First Name' ); | |
$columns['wcmember_last_name'] = __( 'Last Name' ); | |
return $columns; | |
} | |
add_filter( 'manage_edit-wc_user_membership_columns', 'sv_wc_memberships_add_billing_name_columns', 11 ); | |
function sv_wc_memberships_add_billing_name_column_content( $column, $post_id ) { | |
if ( 'wcmember_first_name' === $column || 'wcmember_last_name' === $column ) { | |
$membership = get_post_meta( $post_id ); | |
if( $order = wc_get_order( $membership['_order_id'][0] ) ) { | |
if( 'wcmember_first_name' === $column ){ | |
echo $order->get_billing_first_name(); | |
} | |
if( 'wcmember_last_name' === $column ){ | |
echo $order->get_billing_last_name(); | |
} | |
} | |
} | |
} | |
add_action( 'manage_wc_user_membership_posts_custom_column', 'sv_wc_memberships_add_billing_name_column_content', 11, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment