php - 我的 WooCommerce 功能都不起作用
问题描述
根据浏览某些 WooCommerce 订单,收集数据,然后通过电子邮件发送结果代码,该代码应该从昨天的所有 WooComerce 订单中汇总它们并通过电子邮件发送给我,但电子邮件打印的所有值均为 0。
<?php
define('WP_USE_THEMES', false);
require( dirname( __FILE__ ) . '/wp-load.php' );
// Date
$yesterday = date( 'Y-m-d', strtotime( ' -1 days ' ) );
// Args
$args = array(
'date_created' => $yesterday,
);
// Get WC orders
$orders = Wc()->wc_get_orders( $args );
// Initialize
$subtotal = 0;
$gratuity = 0;
$taxes = 0;
// NOT empty
if ( ! empty ( $orders ) ) {
foreach ( $orders as $order ) {
// DEBUG information, removed if desired
echo '<p>ID = ' . $order->get_id() . '</p>';
// 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();
}
}
// Send e-mail
$to = 'jesse@munerismedia.com';
$subject = 'Order totals for yesterday';
$body = '<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 );
?>
我想我可能缺少依赖项或其他东西。顺便说一句,这是一个夜间运行的 cron 作业。
解决方案
推荐阅读
- python - 如何识别图像的正确性?
- javascript - 为什么文件上传到服务器时缺少数组声明
- css - CSS Bootstrap 输入文本透明,仅底部边框(Chrome)
- python - {{ domain }} 成为本地电脑上的 example.com
- sql - 如果所有列都为空,则如何设置异常
- c# - 在 Windows WPF 应用程序中设置活动/焦点窗口
- mysql - 如何在mysql中生成价格比较报告
- powershell - 如何使用 ansible 读取 powershell 脚本返回的值
- amazon-web-services - 将现有 EBS 卷与 ECS 上的 Docker REX-Ray 插件一起使用
- javascript - 为什么它说现有索引的未定义错误