• I’m using this custom code to add a filter to require a separate phone number and email for an order if they choose to ship to a different address.

    add_filter( 'woocommerce_checkout_fields' , 'phone_email_shipping_checkout_fields' );
    
    function phone_email_shipping_checkout_fields( $fields ) {
    	 $fields['shipping']['shipping_phone'] = array(
    		'label'     => __('Phone', 'woocommerce'),
    	'required'  => true,
    	'class'     => array('form-row-wide'),
    	'clear'     => true
    	 );
    	 $fields['shipping']['shipping_email'] = array(
    		'label'     => __('Email', 'woocommerce'),
    	'required'  => true,
    	'class'     => array('form-row-wide'),
    	'clear'     => true
    	 );
    
    	 return $fields;
    }

    My question is… what filter or hook do I need to use to add these to the New Order Admin emails as well? I’ve managed to add them to the email after the order details but I’d prefer to include them in the boxes for “Shipping Address” so that it mirrors the “Billing Address” box exactly.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter dpkonofa

    (@dpkonofa)

    Follow up… I was able to manually add these by echoing out the custom field info into emails/email-addresses.php but I’d prefer to add them permanently to the shipping info array so that it displays automatically anywhere this shows up. What hooks can I use to accomplish this? I checked the Hooks reference on the WooCommerce docs site and didn’t find anything useful. 🙁

    Plugin Support Rynald0s.a11n

    (@rynald0s)

    Automattic Happiness Engineer

    Thread Starter dpkonofa

    (@dpkonofa)

    Hi, @rynald0s

    Unfortunately, that doesn’t really answer my question. I’m trying to ensure that these fields show up anywhere that the shipping information for an order is displayed. As I mentioned in my original post and reply, I’ve been able to manually specify these things in emails and templates but I’m having a hard time understanding why there isn’t a way to permanently add this to the shipping information so that it shows up anywhere that information is displayed/requested by the cart.

    To be clear, I’m referring to the box on the emails and in the backend that is displayed if the customer chooses a different shipping address from their billing address.

    Hi dpkonofa,

    I’m trying to get the phone number for shipping address displayed in the new order admin email. I already added a custom field in the checkout form, so I have this meta in the database, but I want to display it in the new order email.
    I think it’s exactly what you’ve tried to do.
    Did you find a solution?

    Many thanks.

    Thread Starter dpkonofa

    (@dpkonofa)

    Hi, @from-scratch!

    I didn’t find a solution to what I was trying to do but I did, in the course of attempting, come up with a way to customize the info that’s in the emails. Woocommerce creates all of its emails using templates that are stored in the “woocommerce” folder of your theme. To edit the addresses in that display in the email, you’ll want to edit this file:

    wp_content -> theme_name -> woocommerce -> emails -> email-addresses.php

    I ended up customizing these quite a bit so I’m not going to post the whole content, but this should be what you’re looking for:

    <address class="address">
    	<table cellspacing="0" cellpadding="0" style="width: 100%; padding:0;" border="0">
    		<tr>
    			<td class="address-td" valign="top">
    				<?php echo wp_kses_post( $shipping ); ?>
    				<?php  if ( $order->shipping_phone ) : ?>
    					<br/><?php echo wc_make_phone_clickable( $order->shipping_phone ); ?>
    				<?php endif; ?>
    				<?php if ( $order->shipping_email ) : ?>
    					<br/><?php echo esc_html( $order->shipping_email ); ?>
    				<?php endif; ?>
    			</td>
    		</tr>
    	</table>
    </address>

    That will echo out the shipping info along with the shipping phone number and shipping email.

    • This reply was modified 3 years, 7 months ago by dpkonofa. Reason: Cleaning up code block

    Thank you so much for your reply.
    I will do that.

    Exactly what I was looking for
    Thank you so much!

    Thread Starter dpkonofa

    (@dpkonofa)

    @wpairwavz – With respect, if this type of functionality is mission critical for your business, you should have a developer on staff to address issues like these. I don’t think making demands is going to get your issue resolved and especially not for what is essentially a free product.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding Shipping Phone/Email to New Order Emails’ is closed to new replies.