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();