Skip to content
Advertisement

Hide shipping address in WooCommerce new order email notification depending on shipping method id

I want to hide the shipping address if the shipping label is called “Pick up at Rockefeller Store” (but to show for other pickup methods).

There are too many ids such as “local_pickup:3” for me to filter through. I enabled the shipping address to be shown in emails/email-addresses.php despite it being a local pickup method.

My code attempt:

<?php
/**
 * Email Addresses
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-addresses.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerceTemplatesEmails
 * @version 3.9.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$text_align = is_rtl() ? 'right' : 'left';
$address    = $order->get_formatted_billing_address();
$shipping   = $order->get_formatted_shipping_address();


?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; padding:0;" border="0">
    <tr>
        <td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; border:0; padding:0;" valign="top" width="50%">
            <h2><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>

            <address class="address">
                <?php echo wp_kses_post( $address ? $address : esc_html__( 'N/A', 'woocommerce' ) ); ?>
                <?php if ( $order->get_billing_phone() ) : ?>
                    <br/><?php echo wc_make_phone_clickable( $order->get_billing_phone() ); ?>
                <?php endif; ?>
                <?php if ( $order->get_billing_email() ) : ?>
                    <br/><?php echo esc_html( $order->get_billing_email() ); ?>
                <?php endif; ?>
            </address>
        </td>
        <?php if ( $shipping ) : ?>
            <td style="text-align:<?php echo esc_attr( $text_align ); ?>; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; padding:0;" valign="top" width="50%">
                <h2><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>

                <address class="address"><?php echo wp_kses_post( $shipping ); ?></address>
            </td>
        <?php endif; ?>
    </tr>
</table>

I need this to be enabled as some of our other pickup methods require it. And I am trying to have it so that if it is solely “Pick up at Rockefeller Store” then it should hide the shipping address in new order WooCommerce email.

How would I filter this based on its text label as shown in the picture?

enter image description here

Advertisement

Answer

$shipping_local_pickup = false;
        if ( $items_totals = $order->get_order_item_totals() ) {
            foreach ( $items_totals as $items_total ) {
                if ( $items_total['value'] == 'Pick Up at Rockefeller Store' && !$shipping_local_pickup ) $shipping_local_pickup = true;
            }
        }   

Adding this to my template worked then setting line 48 to !$shipping_local_pickup

This allows me to choose the phrase “Pick Up at Rockefeller Store” used in the table and not display the shipping address it if it is present.

Answer was taken and edited from Hide shipping address on local pickup in WooCommerce email notifications

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement