From 8df4ec3dc748be64526df8c3eb2fd519dfbae3f7 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Sun, 14 Oct 2018 14:19:22 +0200 Subject: [PATCH] move package validation to seperate function --- .../wiaas/includes/class-wiaas-checkout.php | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php b/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php index 0cd07f4..e202e1a 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-checkout.php @@ -2,6 +2,22 @@ class Wiaas_Checkout { + public static function init(){ + add_action( 'woocommerce_before_checkout_process', array(__CLASS__, 'validate_wiaas_packages')); + } + + public static function validate_wiaas_packages(){ + //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)){ + throw new Exception('Package ' . $item['data']->get_title() . ' cannot be purchased at the moment'); + } + } + } + /** * Process the order checkout. * @@ -18,16 +34,6 @@ class Wiaas_Checkout { 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)){ - throw new Exception('Package ' . $item['data']->get_title() . ' cannot be purchased at the moment'); - } - } - $order_id = WC()->checkout()->create_order(array()); $order = wc_get_order( $order_id ); @@ -101,3 +107,5 @@ class Wiaas_Checkout { } } } + +Wiaas_Checkout::init();