2
我正在使用Woocommerce訂閱,並且我想生成一個表格,顯示所有活動訂閱者及其相關用戶信息。以下代碼只是拉起所有用戶...任何想法如何正確地做到這一點?謝謝! :)WooCommerce訂閱 - 獲取活動訂閱者信息以在表中顯示
<table style="border-collapse: collapse;" border="0" width="450" cellspacing="0" cellpadding="0"><colgroup> <col span="5" width="75" /> </colgroup>
<tbody>
<tr>
<td width="75"><strong>Last Name</strong></td>
<td width="75" height="13"><strong>First Name</strong></td>
<td width="75"><strong>Company</strong></td>
<td width="95"><strong>Phone</strong></td>
<td width="75"><strong>Email</strong></td>
</tr>
<?php
$args = array(
'post_type' => 'shop_subscription', // Subscription post type
'post_status' => 'wc-active', // Active subscription
'order' => 'ASC',
'meta_key' => 'last_name',
'orderby' => 'meta_value',
'numberposts' => -1,
);
// The Query
$user_query = new WP_User_Query($args);
// User Loop
if (! empty($user_query->results)) {
foreach ($user_query->results as $user) {
echo '
<tr>
<td height="13">' . $user->last_name . '</td> <td>' . $user->first_name . '</td> <td>' . $user->billing_company . '</td><td>' . $user->billing_phone . '</td> <td>' . $user->user_email . '</td></tr>' ;
}
} else {
echo 'No users found.';
}
?>
</tbody>
</table>
太棒了!謝謝!!自從名字在名字欄中拉出來之後,我做了一些更改,我需要按姓氏字母順序組織表格。我會在下面發佈更新的代碼。 –
對不起@LoicTheAztec我是新的,我不知道正確的協議!謝謝你的真棒回答! –