• Resolved naturalvibrance

    (@naturalvibrance)


    Hi, Custom field does not appear in shipping address in email. It shows above the address. I used this code to get it to show in the Billing Address, But I need it in the Shipping Address please. The field is called billing_suburb and shipping_suburb

    add_filter( 'woocommerce_order_formatted_billing_address' , 'th56t_woo_custom_order_formatted_billing_address', 10, 2 );
    function th56t_woo_custom_order_formatted_billing_address( $address, $WC_Order ) {
         
         $address['billing_suburb'] = get_post_meta( $WC_Order->get_id(), 'billing_suburb', true );
    
        return $address;
    
    }
    
    add_filter( 'woocommerce_formatted_address_replacements', function( $replacements, $args ){
    	$replacements['{billing_suburb}'] = isset($args['billing_suburb']) ? $args['billing_suburb'] : '';
        return $replacements;
    
    }, 10, 2 );
    
    add_filter( 'woocommerce_localisation_address_formats' , 'woo_includes_address_formats', 10, 1);
    function woo_includes_address_formats($address_formats) {
    	
        $address_formats['default'] = "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{billing_suburb}\n{postcode}\n{country}"; // default address format
    	// Add your country address format here
    	
        return $address_formats;
    
    }

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author ThemeHigh

    (@themehigh)

    Can you please try using the below code?

    add_filter( 'woocommerce_order_formatted_billing_address' , 'th56t_woo_custom_order_formatted_billing_address', 10, 2 );
    function th56t_woo_custom_order_formatted_billing_address( $address, $WC_Order ) {
         
        $address['billing_suburb'] = get_post_meta( $WC_Order->get_id(), 'billing_suburb', true );
         
        return $address;
    
    }
    
    add_filter('woocommerce_order_formatted_shipping_address','th56t_woo_custom_order_formatted_shipping_address',10,2);
    
    function th56t_woo_custom_order_formatted_shipping_address($address, $WC_Order) {
        
        $address['shipping_suburb'] = get_post_meta( $WC_Order->get_id(), 'shipping_suburb', true );
         
        return $address;
    }
    
    add_filter( 'woocommerce_formatted_address_replacements', function( $replacements, $args ){
        $replacements['{billing_suburb}']  = isset($args['billing_suburb']) ? $args['billing_suburb'] : '';
        $replacements['{shipping_suburb}'] = isset($args['shipping_suburb']) ? $args['shipping_suburb'] : '';
        return $replacements;
    
    }, 10, 2 );
    
    add_filter( 'woocommerce_localisation_address_formats' , 'woo_includes_address_formats', 10, 1);
    function woo_includes_address_formats($address_formats) {
        foreach($address_formats as $key => $value) :
            $address_formats[$key] .= "\n{billing_suburb}";
            $address_formats[$key] .= "\n{shipping_suburb}";
        endforeach;
        return $address_formats;
    }

    We hope this helps.

    Thank you!

    Thread Starter naturalvibrance

    (@naturalvibrance)

    This works great thank you. The billing_suburb & shipping_suburb now appears at the bottom of the address. Would have liked it to be just before the City. What code change do I need for that. Thanks

    Plugin Author ThemeHigh

    (@themehigh)

    Please add the below code in your theme’s functions.php file instead of the one that we have provided in our previous reply.

    add_filter( 'woocommerce_order_formatted_billing_address' , 'th56t_woo_custom_order_formatted_billing_address', 10, 2 );
    function th56t_woo_custom_order_formatted_billing_address( $address, $WC_Order ) {
         
        $address['billing_suburb'] = get_post_meta( $WC_Order->get_id(), 'billing_suburb', true );
         
        return $address;
    
    }
    
    add_filter('woocommerce_order_formatted_shipping_address','th56t_woo_custom_order_formatted_shipping_address',10,2);
    
    function th56t_woo_custom_order_formatted_shipping_address($address, $WC_Order) {
        
        $address['shipping_suburb'] = get_post_meta( $WC_Order->get_id(), 'shipping_suburb', true );
         
        return $address;
    }
    
    add_filter( 'woocommerce_formatted_address_replacements', function( $replacements, $args ){
        $replacements['{billing_suburb}']  = isset($args['billing_suburb']) ? $args['billing_suburb'] : '';
        $replacements['{shipping_suburb}'] = isset($args['shipping_suburb']) ? $args['shipping_suburb'] : '';
        return $replacements;
    
    }, 10, 2 );
    
    add_filter( 'woocommerce_localisation_address_formats' , 'woo_includes_address_formats', 10, 1);
    function woo_includes_address_formats($address_formats) {
        foreach($address_formats as $key => $value) :
        	$address_formats[$key] = "{name}\n{company}\n{address_1}\n{address_2}\n{billing_suburb}\n{shipping_suburb}\n{city}\n{state}\n{postcode}\n{country}";
        endforeach;
        return $address_formats;
    }

    You can modify the address format as required.

    We hope this helps.

    Thank you!

    Thread Starter naturalvibrance

    (@naturalvibrance)

    Hi, It work for a little bit but for some reason the Shipping Suburb is not showing on the emails.

    Plugin Author ThemeHigh

    (@themehigh)

    Your issue needs a detailed check. Could you please raise a ticket through our website? We hope our technical team will be able to help you.

    Thank you!

    Plugin Author ThemeHigh

    (@themehigh)

    We hope your issue is resolved.

    We are going to mark this thread as resolved.

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom field showing in wrong place’ is closed to new replies.