From 6f3069bee9c5a16641bb21ae278d149064ddbdd2 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Tue, 9 Jul 2024 14:17:39 -0400 Subject: [PATCH] Handle previous orders without coffees assigned --- wp-content/themes/mont58-coffee/functions.php | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/wp-content/themes/mont58-coffee/functions.php b/wp-content/themes/mont58-coffee/functions.php index 6c366a3..d753f8c 100644 --- a/wp-content/themes/mont58-coffee/functions.php +++ b/wp-content/themes/mont58-coffee/functions.php @@ -152,27 +152,29 @@ function action_wcs_renewal_order_created($order, $subscription) $order_coffees = []; $seen_subscriptions = []; - // Get the latest coffee seen in each coffee list from the previous order - foreach (array_reverse($last_order_coffees) as $last_order_coffee) { - if ( - array_key_exists( - $last_order_coffee["coffee_list"]->ID, - $seen_subscriptions - ) - ) { - continue; + if ($last_order_coffees !== false) { + // Get the latest coffee seen in each coffee list from the previous order + foreach (array_reverse($last_order_coffees) as $last_order_coffee) { + if ( + array_key_exists( + $last_order_coffee["coffee_list"]->ID, + $seen_subscriptions + ) + ) { + 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