I'd like to display the billing address on a custom page on my site. This page contains a list of users with some of their registered information, but I would also like to display address information these users...
To do this, I created a custom template with this code:
<?php
/* Template Name: List Users */
get_header(); ?>
<div id="primary">
<main id="main" role="main">
<div id="pageTitle">
<h2>Onde Comprar</h2>
</div>
<div id="pageText">
<p>
A Editora Conclave distribui e tem parcerias com vários lojistas pelo Brasil, você pode localizar a loja mais próxima a você ou se preferir poderá comprar na nossa loja virtual, <a href="https://conclaveweb.com.br/loja/">clicando aqui</a>.
</p>
</div>
<div id="searchContainer"></div>
<ul id="userListContainer">
<?php
// WP_User_Query arguments
$args = array(
'meta_key' => 'first_name',
'role' => 'shopkeeper',
//'search' => 'first_name',
'search_columns' => array('first_name', 'city', 'state'),
'order' => 'ASC',
'orderby' => 'meta_value',
'fields' => 'all_with_meta',
);
// The User Query
$users = new WP_User_Query($args);
// User Loop
if (!empty($users->results)) {
foreach ($users->results as $user) {
echo
//get_author_posts_url( $user->ID ) . the_author_meta( 'user_url', $user->ID ) .
'<li>' .
'<a href="' . esc_url(get_author_posts_url($user->ID)) . '">' .
'<div id="userImage">' . get_avatar($user->ID) . '</div>' .
'<div id="userInfo">' . esc_attr($user->first_name) . ' ' . esc_attr($user->last_name) . '<br>' .
'CEP: ' . esc_attr($user->post_code) . ' — ' . esc_attr($user->city) . ', ' . esc_attr($user->state) . '<br>' .
'</a>' .
'<a href="' . esc_attr($user->user_url) . '">' . esc_attr($user->user_url) . '</a>' .
'</div>' .
'</li>';
}
} else {
echo 'Nenhum usuário encontrado.';
}
?>
</ul>
</main><!-- #main -->
</div><!-- #primary -->
<?php
//do_action( 'ekommart_sidebar' );
get_footer();
?>
I tryed display the address, but don`t work. I believe that dont work because this informations does not come by "WP_User_Query", but do not know how bring them.
Any help will be welcome! Thank’s!!
CodePudding user response:
This may help you:
// Get the user ID from an Order ID
$user_id = get_post_meta( $order_id, '_customer_user', true );
// Get an instance of the WC_Customer Object from the user ID
$customer = new WC_Customer( $user_id );
$username = $customer->get_username(); // Get username
$user_email = $customer->get_email(); // Get account email
$first_name = $customer->get_first_name();
$last_name = $customer->get_last_name();
$display_name = $customer->get_display_name();
// Customer billing information details (from account)
$billing_first_name = $customer->get_billing_first_name();
$billing_last_name = $customer->get_billing_last_name();
$billing_company = $customer->get_billing_company();
$billing_address_1 = $customer->get_billing_address_1();
$billing_address_2 = $customer->get_billing_address_2();
$billing_city = $customer->get_billing_city();
$billing_state = $customer->get_billing_state();
$billing_postcode = $customer->get_billing_postcode();
$billing_country = $customer->get_billing_country();
// Customer shipping information details (from account)
$shipping_first_name = $customer->get_shipping_first_name();
$shipping_last_name = $customer->get_shipping_last_name();
$shipping_company = $customer->get_shipping_company();
$shipping_address_1 = $customer->get_shipping_address_1();
$shipping_address_2 = $customer->get_shipping_address_2();
$shipping_city = $customer->get_shipping_city();
$shipping_state = $customer->get_shipping_state();
$shipping_postcode = $customer->get_shipping_postcode();
$shipping_country = $customer->get_shipping_country();