diff --git a/includes/Order/Hooks.php b/includes/Order/Hooks.php index 6bbc834613..0152088ef9 100644 --- a/includes/Order/Hooks.php +++ b/includes/Order/Hooks.php @@ -322,14 +322,20 @@ public function ensure_vendor_coupon( $valid, $coupon, $discount ) { $available_vendors = []; $available_products = []; - if ( WC()->cart ) { + if ( WC()->cart && ! WC()->cart->is_empty() ) { foreach ( WC()->cart->get_cart() as $item ) { $product_id = $item['data']->get_id(); $available_vendors[] = (int) dokan_get_vendor_by_product( $product_id, true ); $available_products[] = $product_id; } } else { - foreach ( $discount->get_items() as $item_id => $item ) { + foreach ( $discount->get_items() as $item ) { + if ( ! isset( $item->product ) || ! $item->product instanceof \WC_Product ) { + continue; + } + + $item_id = $item->product->get_id(); + $available_vendors[] = (int) dokan_get_vendor_by_product( $item_id, true ); $available_products[] = $item_id; }