Handle previous orders without coffees assigned
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
3wc 2024-07-09 14:17:39 -04:00
parent cd14c04689
commit 6f3069bee9

View File

@ -152,27 +152,29 @@ function action_wcs_renewal_order_created($order, $subscription)
$order_coffees = []; $order_coffees = [];
$seen_subscriptions = []; $seen_subscriptions = [];
// Get the latest coffee seen in each coffee list from the previous order if ($last_order_coffees !== false) {
foreach (array_reverse($last_order_coffees) as $last_order_coffee) { // Get the latest coffee seen in each coffee list from the previous order
if ( foreach (array_reverse($last_order_coffees) as $last_order_coffee) {
array_key_exists( if (
$last_order_coffee["coffee_list"]->ID, array_key_exists(
$seen_subscriptions $last_order_coffee["coffee_list"]->ID,
) $seen_subscriptions
) { )
continue; ) {
continue;
}
$position_in_list = array_search(
$last_order_coffee["coffee"]->ID,
$last_order_coffee["coffee_list"]->coffees
);
if ($position_in_list === false) {
// ignore this, can't find it in list anymore
continue;
}
$seen_subscriptions[
$last_order_coffee["coffee_list"]->ID
] = $position_in_list;
} }
$position_in_list = array_search(
$last_order_coffee["coffee"]->ID,
$last_order_coffee["coffee_list"]->coffees
);
if ($position_in_list === false) {
// ignore this, can't find it in list anymore
continue;
}
$seen_subscriptions[
$last_order_coffee["coffee_list"]->ID
] = $position_in_list;
} }
// Process coffee items based on the coffees in the last order // Process coffee items based on the coffees in the last order