Magento 2 How to get Customer Shipping Address Street Line 2 details

To get Customer address street second line details from magento 2 we need to split the data as the

data is present in the form of an array, so you can store values in the variable and split the value of


the array to get the customer street address details , the below code logic might help you to get the details




    $orderId = 1;


    
     $orderDetailsArray = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);


     
      $shippingDetailsData =$orderDetailsArray->getShippingAddress();



$customerStreet = $shippingDetailsData->getStreet();



#get customer shipping street



#get order details shipping address line 1
print_r($customerStreet[0]);




#get order details shipping address line 2
        print_r($customerStreet[1]);




Explanation for the above code is given below , first we are loading the order object . For the order object

we will pass the order id of the order increment id , the following order id loads the data from the database

tables, when the data is loaded we will try to get the shipping details of the customer from the order details

by using the following method $orderDetailsArray->getShippingAddress();  

The shipping address loads the complete shipping information of the order, when you try to get the 

street details from the shippingAddress object and try to echo you will get a Notice : Array to string 

conversion in line number on your screen , this is becuase the street details is present in the form of 

the array, to get the details of the array , you will need to parse the array , so we can store it one 

variable  called as $customerStreet  , the following details can be passed by using the key of the 

array and you will be able to echo the customer street 1 and customer street line 2 from the 

address details