get_currency() ) { /* translators: %s: currency code. */ return sprintf( __( 'The order currency is %s. ABS Courier only accepts orders in EGP.', 'abs-courier' ), $order->get_currency() ); } $address = OrderMapper::address( $order ); if ( '' !== $address['country'] && 'EG' !== $address['country'] ) { return __( 'ABS Courier only delivers within Egypt.', 'abs-courier' ); } if ( ! self::has_shippable_items( $order ) ) { return __( 'The order has nothing to ship (only virtual or downloadable products).', 'abs-courier' ); } if ( $automatic && self::is_local_pickup( $order ) ) { return __( 'The customer chose local pickup.', 'abs-courier' ); } return ''; } /** * Whether at least one line item needs shipping. * * @param \WC_Order $order Order. * @return bool */ private static function has_shippable_items( \WC_Order $order ) { foreach ( $order->get_items() as $item ) { $product = $item instanceof \WC_Order_Item_Product ? $item->get_product() : null; if ( ! $product || $product->needs_shipping() ) { return true; } } return false; } /** * Whether the order's shipping method is a pickup method. * * @param \WC_Order $order Order. * @return bool */ private static function is_local_pickup( \WC_Order $order ) { foreach ( $order->get_shipping_methods() as $method ) { if ( in_array( $method->get_method_id(), array( 'local_pickup', 'pickup_location' ), true ) ) { return true; } } return false; } }