• Hello,

    We added 2 custom fields to our shipping adress with this functions :

    	// display shipping phone in checkout and my account edit shipping address
    	add_filter( 'woocommerce_shipping_fields', 'add_shipping_phone_field' );
    	function add_shipping_phone_field( $fields ) {
    	   $fields['shipping_phone'] = array(
    		  'label' => __('N° de téléphone du destinataire'),
    		  'required' => true,
    		  'class' => array( 'form-row-wide' ),
    		  'priority' => 100,
    	   );
    	   $fields['shipping_mail'] = array(
    		  'label' => __('Email du destinataire'),
    		  'required' => false,
    		  'class' => array( 'form-row-wide' ),
    		  'priority' => 100,
    	   );   
    	   
    	   return $fields;
    	}
    
    	// Editable field on admin order edit pages inside edit shipping section
    	add_filter( 'woocommerce_admin_shipping_fields' , 'add_order_admin_edit_shipping_phone' );
    	function add_order_admin_edit_shipping_phone( $fields ) {
    		// Include shipping phone as editable field
    		$fields['phone'] = array( 'label' => __("Téléphone"), 'show' => '0' );
    		$fields['mail'] = array( 'label' => __("Email"), 'show' => '0' );
    
    		return $fields;
    	}
    
    	// Adding custom placeholder to woocommerce formatted address only on Backend
    	add_filter( 'woocommerce_localisation_address_formats', 'admin_localisation_address_formats', 50, 1 );
    	function admin_localisation_address_formats( $address_formats ){
    		// Only in backend (Admin)
    		if( is_admin() || ! is_wc_endpoint_url() ) {
    			foreach( $address_formats as $country_code => $address_format ) {
    				$address_formats[$country_code] .= "\n{phone}";
    				$address_formats[$country_code] .= "\n{mail}";
    			}
    		}
    		return $address_formats;
    	}
    
    	// Custom placeholder replacement to woocommerce formatted address
    	add_filter( 'woocommerce_formatted_address_replacements', 'custom_formatted_address_replacements', 10, 2 );
    	function custom_formatted_address_replacements( $replacements, $args  ) {
    		$replacements['{phone}'] = ! empty($args['phone']) ? $args['phone'] : '';
    		$replacements['{mail}'] = ! empty($args['mail']) ? $args['mail'] : '';
    
    		return $replacements;
    	}
    
    	// Add the shipping phone value to be displayed on email notifications under shipping address
    	add_filter( 'woocommerce_order_formatted_shipping_address', 'add_shipping_phone_to_formatted_shipping_address', 100, 2 );
    	function add_shipping_phone_to_formatted_shipping_address( $shipping_address, $order ) {
    		global $pagenow, $post_type;
    
    		// Not on admin order edit pages (as it's already displayed).
    		if( ! ( $pagenow === 'post.php' && $post_type === 'shop_order' && isset($_GET['action']) && $_GET['action'] === 'edit' ) ) {
    			// Include shipping phone on formatted shipping address
    			$shipping_address['phone'] = $order->get_meta('_shipping_phone');
    			$shipping_address['mail'] = $order->get_meta('_shipping_mail');
    		}
    		return $shipping_address;
    	}
    
    	// Remove double billing phone from email notifications (and admin) under billing address
    	add_filter( 'woocommerce_order_formatted_billing_address', 'remove_billing_phone_from_formatted_billing_address', 100, 2 );
    	function remove_billing_phone_from_formatted_billing_address( $billing_address, $order ) {
    		unset($billing_address['phone']);
    		unset($billing_address['mail']);
    	  
    		return $billing_address;
    	}

    I don’t know why, but in packing slip, those two detail goes to the good place, perhaps billing phone & billing e-mail are going to the wrong column :

    you can see a capture here : https://ibb.co/DpJpvRc

    The information in RED should go under biling adress.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Because 1) billing phone and email are by default not included in the formatted address and 2) there is no shipping phone number by default, I wonder if the phone number you see there may simply be the default phone and email that our plugin prints there, following these settings:

    Can you make sure these settings are disabled (and also enable Test mode)?

    Your code (woocommerce_order_formatted_billing_address) only removes the billing phone and email from the formatted address, it does not add anything (like you do for the shipping address).

    Thread Starter HimSelf (Gregory)

    (@himself)

    It’s not default information, it’s the information defined by client.

    if i remove requested option (display e-mail & phone) it looks better, but this mean we don’t have billing phone & mail in case of problem with the order.

    I’m sure there is a way to display it under the billing adress ??

    Thread Starter HimSelf (Gregory)

    (@himself)

    Uffff,

    i’m stupid, i haven’t look to the template.

    Just had to moove :

    			<?php if ( isset($this->settings['display_email']) ) { ?>
    			<div class="billing-email"><?php $this->billing_email(); ?></div>
    			<?php } ?>
    			<?php if ( isset($this->settings['display_phone']) ) { ?>
    			<div class="billing-phone"><?php $this->billing_phone(); ?></div>
    			<?php } ?>

    from shipping adress to billing adress… !

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘added shipping phone + email, but billing e-mail & phone display wrong’ is closed to new replies.