move package validation to seperate function

This commit is contained in:
Bilal Catic
2018-10-14 14:19:22 +02:00
parent 4bdad78ed8
commit 8df4ec3dc7

View File

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