From 4a18042a6204aad444a999b1564f86b3eda34a87 Mon Sep 17 00:00:00 2001 From: thelastpoet Date: Wed, 16 Aug 2023 16:11:33 +0300 Subject: [PATCH] Fixed Issue #60 --- src/Utilities.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Utilities.php b/src/Utilities.php index e9a7d2e..0579128 100644 --- a/src/Utilities.php +++ b/src/Utilities.php @@ -125,19 +125,25 @@ public function wc_mpesa_order_list_column_content($column) } } + /** + * Fixed Issue - https://github.com/osenco/osen-wc-mpesa/issues/60#issue-1661328791 + * + * first check if $order is an instance of WC_Order. If not, return the original $attachments. + * + */ public function woocommerce_emails_attach_downloadables(array $attachments, $status, $order) { - if (is_object($order) || isset($status) || !empty($order)) { - if (is_a($order, 'WC_Order') && method_exists($order, 'has_downloadable_item')) { - if ($order->has_downloadable_item()) { - - $allowed_statuses = array('customer_invoice', 'customer_completed_order'); - if (isset($status) && in_array($status, $allowed_statuses)) { - foreach ($order->get_items() as $item) { - foreach ($order->get_item_downloads($item) as $download) { - $attachments[] = str_replace(content_url(), WP_CONTENT_DIR, $download['file']); - } - } + // Check if the $order is an instance of WC_Order + if (!($order instanceof \WC_Order)) { + return $attachments; + } + + if ($order->has_downloadable_item()) { + $allowed_statuses = array('customer_invoice', 'customer_completed_order'); + if (isset($status) && in_array($status, $allowed_statuses)) { + foreach ($order->get_items() as $item) { + foreach ($order->get_item_downloads($item) as $download) { + $attachments[] = str_replace(content_url(), WP_CONTENT_DIR, $download['file']); } } } @@ -145,4 +151,5 @@ public function woocommerce_emails_attach_downloadables(array $attachments, $sta return $attachments; } + }