The purpose of my code is to go through all orders from yesterday. Then I want the:
- subtotal
- tax
- gratuity
count together and then send the results via the WordPress wp_mail() function.
For some reason it never even sends an email. Can someone tell me what is wrong with my code? do I miss something? any advice?
<?php
define('WP_USE_THEMES', false);
require( dirname( __FILE__ ) . '/wp-load.php' );
function dcwd_status_set_html_content_type() {
return 'text/html';
}
$yesterday = date( 'Y-m-d', strtotime( '-1 days' ) );
$args = array(
'date_created' => $yesterday,
);
$orders = wc_get_orders( $args );
$subtotal = 0.0;
$gratuity = 0.0;
$taxxes = 0.0;
if ( count( $orders ) ) {
$orders_by_status = array();
foreach ( $orders as $order ) {
$eachordersubtotal = $order->get_subtotal();
$eachordersubtotal + $subtotal;
$eachordergratuity = $order->get_fees();
$eachordergratuity + $gratuity;
$eachordertaxxes = $order->get_taxxes();
$eachordertaxxes + $taxxes;
}
$subtotalstring = sprintf("%.3f", $subtotal);
$gratuitystring = sprintf("%.3f", $gratuity);
$taxxesstring = sprintf("%.3f", $taxxes);
$to = 'myname@myemail.com';
$subject = 'Order totals for yesterday';
$body = $subtotalstring, $gratuitystring, $taxxesstring;
wp_mail($to, $subject, $body)
?>