php - 我在这段代码中的 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。要全部获取它们,您需要将 limit 选项添加到您的 args 数组中:
$args = array(
'limit' => -1,
'date_created' => $today,
);
$orders = wc_get_orders( $args );
推荐阅读
- android - 活动结束后,BroadcastReceiver 不再触发
- laravel - Laravel:Amazon Web Service 将时区更改为 UTC
- vuejs2 - vuejs 动态渲染图像
- c# - msbuild 不会在发布配置中构建
- django - Django:尝试实现不区分大小写的用户名但不工作
- android - CMake 错误:在 EnableLanguage 之后未设置 CMAKE_C_COMPILER
- linq - 在 DbContext 上构建过滤器
- javascript - 使用 node js、express 和 OracleDB 创建 API
- unix - PL/I 程序中的 z/OS MVS 和 z/OS UNIX 互操作?
- android - 数据未显示在列表中