Replies: 0
I’m trying to send a daily report through the printer and am having trouble any guidance would be extremely appreciated. the code below is running as a cron job on my server daily in order to try and total up the order data and print it.
<?php
define('WP_USE_THEMES', false);
require( dirname( __FILE__ ) . '/wp-load.php' );
// Date
date_default_timezone_set('PST');
$today = date( 'Y-m-d', strtotime( ' -1 days ' ) );
// Args
$args = array(
'limit' => -1,
'date_created' => $today,
);
// Get WC orders
$orders = \wc_get_orders( $args );
// Initialize
$subtotal = 0;
$fees = 0;
$taxes = 0;
$convenience = 0;
// NOT empty
if ( ! empty ( $orders ) ) {
foreach ( $orders as $order ) {
echo $order->get_id();
// Get subtotal
$subtotal += $order->get_subtotal();
$convenience += round($order->get_subtotal() * .04, 2);
// Get fees
foreach ( $order->get_fees() as $fee_id => $fee ) {
$fees += round($fee['line_total'], 2);
}
// Get tax
$taxes += $order->get_total_tax();
}
}
$gratuity = $fees - $convenience;
$gross = $subtotal + $fees + $taxes;
$net = $subtotal + $convenience;
$WCnet = $subtotal + $fees;
echo 'Date = ' . $today . ' subtotal = ' . $subtotal . ' fees = ' . $fees . ' Taxes = ' . $taxes . 'convenience = ' . $convenience . 'gratuity = ' . $gratuity . 'Gross = ' . $gross . 'net = ' . $net . 'WC net = ' . $WCnet . '';
// Send e-mail
$printer->add_new_text_line("Totals for" . $today .)
$printer->add_new_text_line(' Subtotal = ' . $subtotal .)
$printer->add_new_text_line(' Gross = ' . $gross .)
$printer->add_new_text_line(' Gratuity = ' . $gratuity .)
$printer->add_new_text_line(' Taxes = ' . $taxes .)
$printer->add_new_text_line(' Fees = ' . $fees .)
$printer = star_cloudprnt_command_generator($selectedPrinter, $file);
$printer->set_codepage(get_option('star-cloudprnt-printer-encoding-select'));
$copies=intval(get_option("star-cloudprnt-print-copies-input"));
if($copies < 1) $copies = 1;
$printer->printjob($copies);
?>