Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get shipping address from order, woo commerce

Tags:

woocommerce

Hello I cant get from woocommerce order shipping address, I get error:

Fatal error: Call to a member function get_formatted_address() on a non-object in ..

I am using code:

$order_data = new WC_Order('12');

print_r($order_data->get_formatted_shipping_address());
like image 974
andys Avatar asked Apr 08 '15 09:04

andys


People also ask

How can I get customer details from an order in WooCommerce?

There under the customers name you will see a “Users Insights Profile →” link. This links to the WooCommerce customer profile page of the customer who have purchased the order and from there you can get all the customer details that you might need.

How do I find my WooCommerce order URL?

We can use the wc_get_endpoint_url function to get the order received page URL. To show this under your order list on the my-account page, you have to edit the template – woocommerce/templates/my-account/orders.

How do I enable the shipping address in checkout page WooCommerce?

To access the plugin's options menu, go to WooCommerce > Checkout on your WP Admin sidebar. Then select the Force Shipping Address option and adjust it to Yes. On your WooCommerce checkout page, your shipping address should now be visible.

How do I find the shipping ID in WooCommerce?

Alternative Way to Finding the IDRight click on the 'Shipping' box of your checkout page when the option you need is available. The option ID can be found nearby in the source code, as seen below.


1 Answers

Here is a workaround

// 123 Happy Coding Lane, Apt #5 Delray Beach, FL 33445

function formatted_shipping_address($order)
{
    return
        $order->shipping_address_1 . ', ' . 
        $order->shipping_address_2 . ' ' .
        $order->shipping_city      . ', ' .
        $order->shipping_state     . ' ' .
        $order->shipping_postcode;
}

echo formatted_shipping_address($order);

You can access the shipping & billing properties directly.

Shipping

$order->shipping_first_name
$order->shipping_last_name
$order->shipping_company
$order->shipping_address_1
$order->shipping_address_2
$order->shipping_city
$order->shipping_state
$order->shipping_postcode
$order->shipping_country

Billing

$order->billing_first_name
$order->billing_last_name
$order->billing_company
$order->billing_address_1
$order->billing_address_2
$order->billing_city
$order->billing_state
$order->billing_postcode
$order->billing_country
like image 61
im_brian_d Avatar answered Oct 01 '22 10:10

im_brian_d