get_address() public method

Note: Merges raw data with get_prop data so changes are returned too.
Since: 2.4.0
public get_address ( string $type = 'billing' ) : array
$type string Billing or shipping. Anything else besides 'billing' will return shipping address.
return array The stored address after filter.
 public function get_shipping_data()
 {
     $data = [];
     foreach ($this->get_fraktguiden_shipping_items() as $item_id => $method) {
         $pickup_point_id = wc_get_order_item_meta($item_id, '_fraktguiden_pickup_point_id', true);
         $pickup_point = null;
         $pickup_point_cached = null;
         $pickup_point_postcode = null;
         if ($pickup_point_id) {
             $shipping_address = $this->order->get_address('shipping');
             $request = new WP_Bring_Request();
             $response = $request->get('https://api.bring.com/pickuppoint/api/pickuppoint/' . $shipping_address['country'] . '/id/' . $pickup_point_id . '.json');
             $pickup_point = $response->has_errors() ? null : json_decode($response->get_body())->pickupPoint[0];
             $pickup_point_cached = wc_get_order_item_meta($item_id, '_fraktguiden_pickup_point_cached', true);
             $pickup_point_postcode = wc_get_order_item_meta($item_id, '_fraktguiden_pickup_point_postcode', true);
         }
         $data[] = ['item_id' => $item_id, 'pickup_point' => $pickup_point, 'pickup_point_info_cached' => $pickup_point_cached, 'postcode' => $pickup_point_postcode, 'packages' => json_encode($this->get_packages_for_order_item($item_id))];
     }
     return $data;
 }
 /**
  * Update address.
  *
  * @param WC_Order $order
  * @param array $posted
  * @param string $type
  */
 protected function update_address($order, $posted, $type = 'billing')
 {
     $fields = $order->get_address($type);
     foreach (array_keys($fields) as $field) {
         if (isset($posted[$field])) {
             $fields[$field] = $posted[$field];
         }
     }
     // Set address.
     $order->set_address($fields, $type);
     // Update user meta.
     if ($order->get_user_id()) {
         foreach ($fields as $key => $value) {
             update_user_meta($order->get_user_id(), $type . '_' . $key, $value);
         }
     }
 }
Esempio n. 3
0
function handlePaymentCompleted($order_id)
{
    echo "-- handlePaymentCompleted";
    $order = new WC_Order($order_id);
    $customer = new WC_Customer($order_id);
    $addresses = $order->get_address("shipping");
    /*
    $To = get_option('admin_email').",dev_support@soixanteseize.com";
        $Objet = $email_heading = "Vérifiez la commande ".$order_id;
        $message = $response[1];
        ob_start();
        include(COURIIERPATH.'views/mails/woo-couriier-order-ready.php');
        $Body = ob_get_clean();
        trace($Body);
        //sendCC($To, $Objet, $Body);
    
        return;
    */
    $adresse = $addresses["address_1"] . ", ";
    if ($addresses["address_2"] != "") {
        $adresse .= $addresses["address_2"] . ", ";
    }
    $adresse .= $addresses["city"] . " ";
    $adresse .= $addresses["postcode"] . " ";
    //$postcode = $addresses["postcode"];
    //trace($order);
    //trace($customer);
    //trace($order->get_address("shipping") );
    //trace($adresse);
    $chosen_methods = $order->get_shipping_methods();
    if (count($chosen_methods) > 0) {
        //$la_methode = object();
        foreach ($chosen_methods as $c_method) {
            //                trace($method);
            $chosen_method = $c_method['item_meta']['method_id'][0];
        }
        //trace($chosen_method);
        $available_methods = WC()->session->get('shipping_methods_' . $addresses["postcode"]);
        //trace($available_methods);
        $offerIdTarifs = '';
        foreach ($available_methods as $method) {
            //trace($method->speed);
            switch ($method->speed) {
                case 2:
                    if ($chosen_method == 'couriier_classic_shipping_method') {
                        $offerIdTarifs = $method->ref;
                    }
                    break;
                case 1:
                    if ($chosen_method == 'couriier_rapide_shipping_method') {
                        $offerIdTarifs = $method->ref;
                    }
                    break;
                case 0:
                    if ($chosen_method == 'couriier_flash_shipping_method') {
                        $offerIdTarifs = $method->ref;
                    }
                    break;
            }
        }
        //return;
        $adresse = $customer->get_address() . " " . $customer->get_postcode() . ", " . $customer->get_city();
        $recipientLatLng = geoloc($adresse);
        //trace($customer);
        //trace($recipientLatLng);
        //trace($offerIdTarifs);
        //return;
        $body = array(array('offerIdTarifs' => $offerIdTarifs, 'pickupName' => get_bloginfo("name"), 'pickupLatitude' => PICKUPLAT, 'pickupLongitude' => PICKUPLNG, 'pickupAddress' => PICKUPADRESSE, 'pickupAddress2' => "test", 'pickupTel' => PICKUPTEL, 'pickupZip' => PICKUPZIP, 'pickupCity' => PICKUPCITY, 'recipientName' => $order->get_formatted_shipping_full_name(), 'recipientLatitude' => $recipientLatLng["lat"], 'recipientLongitude' => $recipientLatLng["lng"], 'recipientAddress' => $addresses["address_1"], 'recipientAddress2' => $addresses["address_2"], 'recipientTel' => $order->billing_phone, 'recipientZip' => $addresses["postcode"], 'recipientCity' => $addresses["city"], 'timeManagement' => "2015-04-24 00:00:00", 'deliveryType' => "En main propre"));
        //trace($body);
        //return;
        $body = json_encode($body);
        $url = COURIIER_WS . '/orders';
        //trace($url);
        $response = api_call_post($url, $body);
        //trace($response);
        $response = json_decode($response['body']);
        //trace($response);
        $couriier_order_id = $response[0]->id;
        //trace($order_id);
        //return;
        if ($couriier_order_id) {
            /**
                url_order_follow
                    **/
            $url_order_follow = $response[0]->following_url;
            //trace($url_order_follow);
            if ($url_order_follow) {
                $To = $order->billing_email;
                $Objet = $email_heading = "Votre lien pour suivre la livraison Couriier";
                ob_start();
                include COURIIERPATH . 'views/mails/woo-couriier-order-follow.php';
                $Body = ob_get_clean();
                sendCC($To, $Objet, $Body);
            }
            /**
                url_order_ready
                    **/
            $url_rest_order_ready = get_bloginfo("url") . '/wc-api/couriier-order-ready?order_id=' . $order_id . '&couriier_order_id=' . $couriier_order_id;
            //$url_order_ready = COURIIER_WS.'/order/'.$couriier_order_id.'/ready';
            //trace($url_rest_order_ready);
            //return;
            $To = get_option('admin_email') . ",dev_support@soixanteseize.com";
            $Objet = $email_heading = "Votre lien pour lancer la livraison Couriier";
            ob_start();
            include COURIIERPATH . 'views/mails/woo-couriier-order-ready.php';
            $Body = ob_get_clean();
            //trace($Body);
            sendCC($To, $Objet, $Body);
            //return;
        }
    } else {
        $To = get_option('admin_email') . ",dev_support@soixanteseize.com";
        $Objet = $email_heading = "U+026A0 Vérifiez la commande " . $order_id;
        $message = $response[1];
        ob_start();
        include COURIIERPATH . 'views/mails/woo-couriier-blank.php';
        $Body = ob_get_clean();
        //trace($Body);
        sendCC($To, $Objet, $Body);
    }
    //sendCC($To, $Objet, $Body);
}
Esempio n. 4
0
 /**
  * Test: get_address
  */
 function test_get_address()
 {
     $object = new WC_Order();
     $billing = array('first_name' => 'Fred', 'last_name' => 'Flintstone', 'company' => 'Bedrock Ltd.', 'address_1' => '34 Stonepants avenue', 'address_2' => 'Rockville', 'city' => 'Bedrock', 'state' => 'Boulder', 'postcode' => '00001', 'country' => 'US', 'email' => '', 'phone' => '');
     $shipping = array('first_name' => 'Barney', 'last_name' => 'Rubble', 'company' => 'Bedrock Ltd.', 'address_1' => '34 Stonepants avenue', 'address_2' => 'Rockville', 'city' => 'Bedrock', 'state' => 'Boulder', 'postcode' => '00001', 'country' => 'US');
     $object->set_billing_first_name('Fred');
     $object->set_billing_last_name('Flintstone');
     $object->set_billing_company('Bedrock Ltd.');
     $object->set_billing_address_1('34 Stonepants avenue');
     $object->set_billing_address_2('Rockville');
     $object->set_billing_city('Bedrock');
     $object->set_billing_state('Boulder');
     $object->set_billing_postcode('00001');
     $object->set_billing_country('US');
     $object->set_shipping_first_name('Barney');
     $object->set_shipping_last_name('Rubble');
     $object->set_shipping_company('Bedrock Ltd.');
     $object->set_shipping_address_1('34 Stonepants avenue');
     $object->set_shipping_address_2('Rockville');
     $object->set_shipping_city('Bedrock');
     $object->set_shipping_state('Boulder');
     $object->set_shipping_postcode('00001');
     $object->set_shipping_country('US');
     $this->assertEquals($billing, $object->get_address());
     $this->assertEquals($shipping, $object->get_address('shipping'));
 }
 /**
  * Updates address on the subscription if one of them is changed.
  *
  * @param  WC_Order $order The new order
  * @param  WC_Subscription $subscription The original subscription
  */
 public static function maybe_update_subscription_address($order, $subscription)
 {
     if (method_exists($subscription, 'get_address')) {
         $order_billing = $order->get_address('billing');
         $order_shipping = $order->get_address();
         $subscription_billing = $subscription->get_address('billing');
         $subscription_shipping = $subscription->get_address();
     } else {
         $order_billing = wcs_get_order_address($order, 'billing');
         $order_shipping = wcs_get_order_address($order);
         $subscription_billing = wcs_get_order_address($subscription, 'billing');
         $subscription_shipping = wcs_get_order_address($subscription);
     }
     $subscription->set_address(array_diff_assoc($order_billing, $subscription_billing), 'billing');
     $subscription->set_address(array_diff_assoc($order_shipping, $subscription_shipping), 'shipping');
 }
 protected function get_destination_address(WC_Order $order)
 {
     $order_address = $order->get_address('shipping');
     $destination = $this->format_address_for_api($order_address);
     return $destination;
 }
 public function orders()
 {
     DABBA_API_Catch_Request::get()->check_params(array('user_id', 'page', 'limit'));
     $customer_orders = get_posts(array('posts_per_page' => $_POST['limit'], 'offset' => $_POST['limit'] * $_POST['page'], 'meta_key' => '_customer_user', 'meta_value' => $_POST['user_id'], 'post_type' => wc_get_order_types(), 'post_status' => array_keys(wc_get_order_statuses())));
     $orders = array();
     foreach ($customer_orders as $order) {
         $order = new WC_Order($order->ID);
         $order_info = array('order_id' => $order->id, "order_date" => $order->order_date, "total" => $order->get_total(), "status" => $order->get_status(), "items" => $order->get_items(), "payment_method" => $order->payment_method, "billing_address" => $order->get_address('billing'), "shipping_address" => $order->get_address('shipping'));
         $orders[] = $order_info;
     }
     DABBA_API_Output::get()->output(true, 200, '', $orders);
 }