Well, come to find out the "look at all orders within 35 days" is the best way to go in our case, but isn't working correctly with the code above.
What is important is if their list of orders spans MORE than 35 days. Having just more than one order doesn't cut it.
So what I was trying to do is select all orders based on the customer ID with the ID taken from the current orderID from the invoice. Then take date_purchased of all orders produced to see if any order is older than 35 days old from now. #4 below.
If no, then take action
Here's the whole thing and what we use it for for anyone's use....
Check the following and if it meets requirements, display wording at the top of the invoice. We use this one among many other personal features not listed...
1. Checks match of billing/shipping address line 1
2. If order is over a $ threshold of choice
3. Order is not a certain payment module
4. Customer meets requirements of no_history (orders are greater than 35 days old)
PHP Code:
$customers_orders = $db->Execute("select o.orders_id, o.date_purchased
from " . TABLE_ORDERS . " o
where customers_id = '" . (int)$order_check->customers_id . "'");
$days35fromnow = strtotime("+35 days", strtotime("<date-from-db>"));
$no_history = ($customers_orders->fields['date_purchased'] < $days35fromnow);
Further down to display wording on the invoice...
PHP Code:
<?php
$headings_array = array();
if (($order_check->fields['delivery_street_address'] != $order_check->fields['billing_street_address'] and $order_check->fields['delivery_street_address'] != '' &&
$order_check->fields['order_total'] > 100 &&
array_search($order_check->fields['payment_module_code'], array('cc')) == FALSE &&
$no_history)) {
$headings_array[] = "YOUR WORDING HERE";
}
for ($i=0; $i < sizeof($headings_array); $i++) {
echo $headings_array[$i];
if($i+1 < sizeof($headings_array)) {
echo "<br />";
}
}
?>
Bookmarks