Cart - requires shipping function

  • Hi,


    In Perch Shop, at the moment to determine whether the cart has items that require shipping you need to get the cart items and loop through the items. Something like:


    PHP
    1. $cart = perch_shop_cart(['skip-template' => true]);
    2. $require_shipping = false;
    3. foreach($cart['items'] as $item) {
    4. $product_fields = json_decode($item['Product']->productDynamicFields());
    5. if($product_fields->requires_shipping) $require_shipping = true;
    6. }
    7. if(!$require_shipping) {
    8. PerchSystem::redirect('/cart/next-step/');
    9. }


    It would be nice if there was a function like perch_shop_cart_has_shippable_items():


    PHP
    1. if(!perch_shop_cart_has_shippable_items()) {
    2. PerchSystem::redirect('/cart/next-step/');
    3. }
    PHP
    1. if(perch_shop_cart_has_shippable_items()) {
    2. perch_shop_shipping_method_form();
    3. }



    I realise I can use perch_shop_get_shipping_weight() and check whether the weight is over 0, but this assumes that all products that require shipping have a shipping weight set. A more explicit function would be appreciated.



    Thanks