我的for循环在这段代码中的上限是10,你知道为什么吗?



所以我有这个代码,从昨天的woocommerce订单和打印关于他们的信息在一封电子邮件中,由于某种原因,它只通过我的for循环最多10次,我不太明白为什么任何指导将是美妙的。

<?php
define('WP_USE_THEMES', false);

require( dirname( __FILE__ ) . '/wp-load.php' );
// Date
date_default_timezone_set('PST');
$today = date( 'Y-m-d' );
// Args
$args = array(
'date_created' => $today,
);
// Get WC orders
$orders = wc_get_orders( $args );
// Initialize
$subtotal = 0;
$gratuity = 0;
$taxes = 0;
// NOT empty
if ( ! empty ( $orders ) ) {
foreach ( $orders as $order ) {
echo $order->get_id();
// Get subtotal
$subtotal += $order->get_subtotal();

// Get fees
foreach ( $order->get_fees() as $fee_id => $fee ) {
$gratuity += $fee['line_total'];
}
// Get tax
$taxes += $order->get_total_tax();
}
}
$convenience = $gratuity;
$gratuity -= .04 * $subtotal;
echo 'Date = ' . $today . ' Subtotal = ' . $subtotal . ' Convenience Fee' . $convenience . ' Gratuity = ' . $gratuity . ' Taxes = ' . $taxes . '';
// Send e-mail
$to = 'jesse@munerismedia.com';
$subject = 'Order totals for today';
$body = '<p>Date = ' . $today . '</p><p>Subtotal = ' . $subtotal . '</p><p>Gratuity = ' . $gratuity . '</p><p>Taxes = ' . $taxes . '</p>';
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
wp_mail( $to, $subject, $body, $headers );
?>

来自文档(强调我的):

限制接受一个整数:要检索的结果的最大数目或-1表示无限。

默认:站点'posts_per_page'设置。

所以你的posts_per_page设置可能是10。要获取所有的参数,需要在args数组中添加limit选项:

$args = array(
'limit' => -1,
'date_created' => $today,
);
$orders = wc_get_orders( $args );

最新更新