From 8d2b1e52b4b6c206482f71f4c08581a87e2ad018 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Wed, 10 Oct 2018 14:41:57 +0200 Subject: [PATCH] prevent checkout with invalid package --- .../wiaas/includes/class-wiaas-checkout.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php b/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php index ae2324a..5bd6bb9 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php @@ -16,6 +16,20 @@ class Wiaas_Checkout { wc_set_time_limit( 0 ); do_action( 'woocommerce_before_checkout_process' ); + $customer = wp_get_current_user(); + + //check if any package became invalid + $items = WC()->cart->get_cart(); + foreach($items as $item) { + $item_id = $item['data']->get_id(); + if (wc_pb_is_bundle_container_cart_item($item) && + (Wiaas_Package_Status::get_package_status($item_id) !== Wiaas_Package_Status::AVAILABLE)){ + return false; + } + } + + $order_id = WC()->checkout()->create_order(array()); + $order = wc_get_order( $order_id ); // Check if cart empty before proceeding if (WC()->cart->is_empty()) {