Validate that items are from the same country and catalogue

This commit is contained in:
Almira Krdzic
2018-11-06 14:03:58 +01:00
parent 99c203b920
commit a1997a813d

View File

@@ -164,11 +164,35 @@ class Wiaas_Cart {
return false;
}
// TODO: Add validation that only packages from the same country can be added to cart at the same time
update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
// Validate that order contains only stuff for single country
if ( ! WC()->cart->is_empty() ) {
// TODO: Add validation that only packages from the same shop can be added to cart at the same time
update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
$current_country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
if ($country !== $current_country) {
wc_add_notice('Only packages from single country can be purchased at the same time!', 'error');
return false;
}
} else {
update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
}
// Validate that order contains only stuff from single commercial lead / reseller / shop owner
if ( ! WC()->cart->is_empty() ) {
$current_shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
if (absint($shop_owner_id) !== absint($current_shop_owner_id)) {
wc_add_notice('Only packages from single catalogue can be purchased at the same time!', 'error');
return false;
}
} else {
update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
}
$customer_id = wiaas_get_current_user_organization_id();