最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to show order data by multiple ID?

programmeradmin4浏览0评论

I use the code.

<?php
echo '<table>
<thead>
<tr style="font-weight: bold;">
<td style="width: 50%;">Название<br>Сумма взноса</td>
<td style="text-align: center;">Мод игры и<br>Кол-во </td>
<td style="text-align: center;">ID<br>заявки и<br>участника
</td>
<td style="text-align: center;">Вступить<br>в схватку</td>
</tr>
</thead>
<tbody>' ;
$filters = array(
    'post_type' => 'shop_order',
    'post_status' => 'wc-completed',
    'order' => 'ASC',
);
$loop = new WP_Query ($filters);  
while ($loop->have_posts()) {
    $loop->the_post();
    $order = new WC_Order ($loop->post->ID);
    $user = $order->get_user();
    $user_id = $order->get_user_id();

    foreach ($order->get_items() as $key => $lineItem) {

       //uncomment the following to see the full data
               // echo '<pre>';
               // print_r($lineItem);
               // echo '</pre>';
        echo '<tr><td>'. $lineItem['name'] .'</br>';
        echo $lineItem->get_meta('vznos').' - ';
        echo $lineItem['total'] .' руб.</td>';

        echo '<td style="text-align: center;">' .$lineItem->get_meta('mod-igry').'<hr style="padding: 0;margin: 0;color: black;background: #23282d;">';
        echo $lineItem->get_meta('kolichestvo-uchastnikov').'</td>';




        echo '<td style="text-align: center;">'. $lineItem['order_id'] .'<hr style="padding: 0;margin: 0;color: black;background: #23282d;">';
        echo $user_id.'</td>';



        echo '<td style="text-align: center;">Схватка</td></tr>';



        }


}

echo '</tbody></table></br>' ;

?>

What I need to fix in it is that only order data is returned - the ID of which I prescribe forcibly? Here is what I get svary.club/zayavka-na-uchastie

I use the code.

<?php
echo '<table>
<thead>
<tr style="font-weight: bold;">
<td style="width: 50%;">Название<br>Сумма взноса</td>
<td style="text-align: center;">Мод игры и<br>Кол-во </td>
<td style="text-align: center;">ID<br>заявки и<br>участника
</td>
<td style="text-align: center;">Вступить<br>в схватку</td>
</tr>
</thead>
<tbody>' ;
$filters = array(
    'post_type' => 'shop_order',
    'post_status' => 'wc-completed',
    'order' => 'ASC',
);
$loop = new WP_Query ($filters);  
while ($loop->have_posts()) {
    $loop->the_post();
    $order = new WC_Order ($loop->post->ID);
    $user = $order->get_user();
    $user_id = $order->get_user_id();

    foreach ($order->get_items() as $key => $lineItem) {

       //uncomment the following to see the full data
               // echo '<pre>';
               // print_r($lineItem);
               // echo '</pre>';
        echo '<tr><td>'. $lineItem['name'] .'</br>';
        echo $lineItem->get_meta('vznos').' - ';
        echo $lineItem['total'] .' руб.</td>';

        echo '<td style="text-align: center;">' .$lineItem->get_meta('mod-igry').'<hr style="padding: 0;margin: 0;color: black;background: #23282d;">';
        echo $lineItem->get_meta('kolichestvo-uchastnikov').'</td>';




        echo '<td style="text-align: center;">'. $lineItem['order_id'] .'<hr style="padding: 0;margin: 0;color: black;background: #23282d;">';
        echo $user_id.'</td>';



        echo '<td style="text-align: center;">Схватка</td></tr>';



        }


}

echo '</tbody></table></br>' ;

?>

What I need to fix in it is that only order data is returned - the ID of which I prescribe forcibly? Here is what I get svary.club/zayavka-na-uchastie

Share Improve this question edited Jun 21, 2019 at 8:40 Василий Маркин asked Jun 21, 2019 at 8:17 Василий МаркинВасилий Маркин 417 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

Here is the code that does what I needed.

$order_ids = $orders_ids_array ;//array('1762','1763'); // The order_id

echo '<table>
<thead>
<tr style="font-weight: bold;">
<td style="width: 50%;">Название<br>Сумма взноса</td>
<td style="text-align: center;">Мод игры и<br>Кол-во </td>
<td style="text-align: center;">ID<br>заявки и<br>участника
</td>
<td style="text-align: center;">Вступить<br>в схватку</td>
</tr>
</thead>
<tbody>' ;

//echo $order_ids ;
foreach( $order_ids as $order_id ){
    // get an instance of the WC_Order object
    $order = new WC_Order( $order_id );
    $user = $order->get_user();
    $user_id = $order->get_user_id();
    // The loop to get the order items which are WC_Order_Item_Product objects since WC 3+
    foreach( $order->get_items() as $item_id => $lineItem ){
        echo '<tr><td>'. $lineItem['name'] .'</br>';
        echo $lineItem->get_meta('vznos').' - ';
        echo $lineItem['total'] .' руб.</td>';
        echo '<td style="text-align: center;">' .$lineItem->get_meta('mod-igry').'<hr style="padding: 0;margin: 0;color: black;background: #23282d;">';
        echo $lineItem->get_meta('kolichestvo-uchastnikov').'</td>';
        echo '<td style="text-align: center;">'. $lineItem['order_id'] .'<hr style="padding: 0;margin: 0;color: black;background: #23282d;">';
        echo $user_id.'</td>';
        echo '<td style="text-align: center;">Схватка</td></tr>';
    } 
}
echo '</tbody></table></br>' ;

Here is an example.

发布评论

评论列表(0)

  1. 暂无评论