How to set the map’s origin address to the customer’s billing address

0 minutes, 33 seconds

Some stores offer the ability for a customer to place an order and have an item picked up from one location (billing address) and then delivered to another address (shipping address).

By using one of the included filters in our Delivery Drivers for WooCommerce plugin you are able to change the origin address in your delivery driver’s map on the order details page.

ddwc_google_maps_origin_address

Add the code snippet below to your theme’s functions.php file and it will set your origin address to the customer’s billing address.

<?php
/**
* Change the origin address in the driver dashboard
* to display the customer's Billing Address
*
* @author Robert DeVore <deviodigital@gmail.com>
* @link https://www.wordpress.org/plugins/delivery-drivers-for-woocommerce/
* @return string
*/
function acme_google_maps_origin_address( $store_address ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $_GET['orderid'] );
// Get the order data.
$order_data = $order->get_data();
// Specific order data.
$order_billing_address_1 = $order_data['billing']['address_1'];
$order_billing_address_2 = $order_data['billing']['address_2'];
$order_billing_city = $order_data['billing']['city'];
$order_billing_state = $order_data['billing']['state'];
$order_billing_country = $order_data['billing']['country'];
$order_billing_postcode = $order_data['billing']['postcode'];
$store_address = $order_billing_address_1 . ' ' . $order_billing_address_2 . ' ' . $order_billing_city . ' ' . $order_billing_state . ' ' . $order_billing_country . ' ' . $order_billing_postcode;
return $store_address;
}
add_filter( 'ddwc_google_maps_origin_address', 'acme_google_maps_origin_address' );

View all filters for the Delivery Drivers for WooCommerce plugin.

Was this article helpful?