小编Sku*_*urt的帖子

如何在fputcsv中使用foreach?

我正在尝试将具有特定订单状态的woocommerce订单详细信息导出到文本文件中.我的问题是,它只会获得一个订单的详细信息,因为我没有使用foreach.有谁知道我如何更改我的代码,以便它将在单独的行中获得所有订单?

define('WP_USE_THEMES', false);
require('/var/www/html/wp-blog-header.php');

global $wpdb;
global $woocommerce;
$args = array(
    'post_type'         => 'shop_order',
    'post_status'       => 'publish',
            'posts_per_page' => -1,
    'tax_query' => array(
                array(
                    'taxonomy' => 'shop_order_status',
                    'field' => 'slug',
                    'terms' => array('processing')
                )
            )
);

$my_query = new WP_Query($args);
$orders = $my_query->posts;
foreach($orders as $order)
{
$order_id = $order->ID;
    $billing_first_name =get_post_meta($order_id,'_billing_first_name',true);
    $billing_last_name = get_post_meta($order_id,'_billing_last_name',true);
    $billing_name = $billing_first_name. " ". $billing_last_name ;
    $billing_address = get_post_meta($order_id,'_billing_address_1',true);
    $billing_address2 = get_post_meta($order_id,'_billing_address_2',true);
    $billing_city = get_post_meta($order_id,'_billing_city',true);
    $billing_postcode = get_post_meta($order_id,'_billing_postcode',true);
    $billing_country = get_post_meta($order_id,'_billing_country',true);
    $billing_email = get_post_meta($order_id,'_billing_email',true); …
Run Code Online (Sandbox Code Playgroud)

php wordpress foreach fputcsv woocommerce

5
推荐指数
1
解决办法
1030
查看次数

标签 统计

foreach ×1

fputcsv ×1

php ×1

woocommerce ×1

wordpress ×1