• Resolved davejwnz

    (@davejwnz)


    When exporting orders the billing and shipping address does not have a space after the persons name, the Street etc – so these are not usable.

    Is there a function I can add to fix these addresses.

    Current shows as:
    john Smith20 Somewhere StreetAuckland 0630

    Should be:
    john Smith, 20 Somewhere Street, Auckland 0630

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Add this snippet to your site –

    add_filter( 'wcfm_orderlist_billing_address', function( $billing_address, $order_id ) {
    	$order = wc_get_order( $order_id );
    	$raw_address = $order->get_address( 'billing' );
    	unset( $raw_address['first_name'], $raw_address['last_name'], $raw_address['company'] );
    	$address     = WC()->countries->get_formatted_address( $raw_address );
    	$billing_address = wp_kses( $address, array( 'br' => array() ) );
    	return $billing_address;
    }, 50, 2 );
    add_filter( 'wcfm_orderlist_shipping_address', function( $shipping_address, $order_id ) {
    	$order = wc_get_order( $order_id );
    	$raw_address = $order->get_address( 'shipping' );
    	unset( $raw_address['first_name'], $raw_address['last_name'], $raw_address['company'] );
    	$address     = WC()->countries->get_formatted_address( $raw_address );
    	$shipping_address = wp_kses( $address, array( 'br' => array() ) );
    	return $shipping_address;
    }, 50, 2 );

    Add custom code(s) to your child theme’s functions.php
    In case you do not have child theme then add those using this plugin –?https://www.ads-software.com/plugins/code-snippets/

    Thread Starter davejwnz

    (@davejwnz)

    Thanks for flicking this through.

    On testing this snippet it removes the first and last name from being exported at all in the orders and does not add a comma after the street address.

    I wanted to get the export as “john Smith, 20 Somewhere Street, Auckland 0630”
    But this snippet now only shows: “20 Somewhere StreetAuckland 0630” – so the same address it has just removed the customers name.

    Plugin Author WC Lovers

    (@wclovers)

    Use this revised snippet –

    add_filter( 'wcfm_orderlist_billing_address', function( $billing_address, $order_id ) {
    	$order = wc_get_order( $order_id );
    	$raw_address = $order->get_address( 'billing' );
    	unset( $raw_address['company'] );
    	$address     = WC()->countries->get_formatted_address( $raw_address );
    	$billing_address = wp_replace_in_html_tags( wp_kses( $address, array( 'br' => array() ) ), array( '<br' => ', ', '>' => '', '/' => '' ) );
    	return $billing_address;
    }, 50, 2 );
    add_filter( 'wcfm_orderlist_shipping_address', function( $shipping_address, $order_id ) {
    	$order = wc_get_order( $order_id );
    	$raw_address = $order->get_address( 'shipping' );
    	unset( $raw_address['company'] );
    	$address     = WC()->countries->get_formatted_address( $raw_address );
    	$shipping_address = wp_replace_in_html_tags( wp_kses( $address, array( 'br' => array() ) ), array( '<br' => ', ', '>' => '', '/' => '' ) );
    	return $shipping_address;
    }, 50, 2 );
    • This reply was modified 4 years ago by WC Lovers.
    Thread Starter davejwnz

    (@davejwnz)

    That does not work either, as it removes the addresses from the export all together and just leaves the customers name in the address columns.

    Thread Starter davejwnz

    (@davejwnz)

    Sorry, that does work perfectly, just had to copy the code correctly.

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Export orders’ is closed to new replies.