Snippets

Visser Labs Add a single Order export field with all Billing address details

Created by Michael Visser
<?php
function custom_woo_ce_extend_order_fields( $fields ) {

	$fields[] = array(
		'name' => 'billing_address_full',
		'label' => 'Billing: All details',
		'hover' => 'Custom Order field within functions.php'
	);
	return $fields;

}
add_filter( 'woo_ce_order_fields', 'custom_woo_ce_extend_order_fields' );

function custom_woo_ce_extend_order( $order, $order_id ) {

    $order->billing_address_full = '';
	$order->billing_address_full .= $order->billing_address . "\n";
	if( !empty( $order->billing_city ) )
		$order->billing_address_full .= $order->billing_city . "\n";
	if( !empty( $order->billing_postcode ) )
		$order->billing_address_full .= $order->billing_postcode . "\n";
	if( !empty( $order->billing_state ) )
		$order->billing_address_full .= $order->billing_state . "\n";
	if( !empty( $order->billing_country ) )
		$order->billing_address_full .= $order->billing_country;

    return $order;

}
add_filter( 'woo_ce_order', 'custom_woo_ce_extend_order', 10, 2 );
?>

Comments (0)