WooCommerce: Add Optional Checkout Email CC: Field

marker, checkbox, red, checkbox, checkbox, checkbox, checkbox, checkbox

In a recent Business Bloomer Club Slack thread, a member asked how to let customers optionally enter a second email address at checkout—specifically if they want WooCommerce emails sent to someone else too.

Their goal was to display a checkbox labeled “Send to another email address,” and, if checked, reveal an additional email field. Any email entered here should be CCed on all WooCommerce order emails.

This is a common request for B2B stores or for people who manage orders on behalf of others, such as virtual assistants, procurement officers, or accounting teams. The good news? This can be achieved without installing yet another plugin.

In this post, we’ll show you how to add a custom checkbox and email field at checkout, use JavaScript to conditionally show the field, save the additional email in the order meta and CC that email on all WooCommerce transactional emails.

Let’s get it done with a few clean snippets.

Add the Checkbox and Conditional Email Field

We first inject a checkbox and an extra email field into the billing section. The email field will be hidden by default.

add_action('woocommerce_after_checkout_billing_form', 'bbloomer_add_cc_email_checkbox');

function bbloomer_add_cc_email_checkbox($checkout) {
    echo '<div id="additional_email_section"><h3>' . __('Additional Email') . '</h3>';

    woocommerce_form_field('add_cc_email_checkbox', array(
        'type'    => 'checkbox',
        'class'   => array('form-row-wide'),
        'label'   => __('Send to another email address'),
    ), $checkout->get_value('add_cc_email_checkbox'));

    woocommerce_form_field('cc_email_address', array(
        'type'        => 'email',
        'class'       => array('form-row-wide'),
        'label'       => __('Additional Email Address'),
        'placeholder' => __('you@example.com'),
        'required'    => false,
    ), $checkout->get_value('cc_email_address'));

    echo '</div>';
}

Add JavaScript to Show/Hide the Email Field

To make the experience dynamic, we hide the email input unless the checkbox is ticked:

add_action('wp_footer', 'bbloomer_cc_email_checkout_script');

function bbloomer_cc_email_checkout_script() {
    if (is_checkout()) :
    ?>
    <script>
    jQuery(function($){
        var checkbox = $('#add_cc_email_checkbox');
        var emailField = $('#cc_email_address_field');
        
        emailField.hide();

        checkbox.change(function(){
            if ($(this).is(':checked')) {
                emailField.show();
            } else {
                emailField.hide();
            }
        });
    });
    </script>
    <?php
    endif;
}

Save the Field Value to the Order

Once submitted, we store the optional email address in the order metadata:

add_action('woocommerce_checkout_update_order_meta', 'bbloomer_save_cc_email_address');

function bbloomer_save_cc_email_address($order_id) {
    if (!empty($_POST['cc_email_address'])) {
        update_post_meta($order_id, '_cc_email_address', sanitize_email($_POST['cc_email_address']));
    }
}

Add the CC to WooCommerce Emails

We now retrieve that value and use it as a CC recipient for all WooCommerce transactional emails:

add_filter('woocommerce_email_headers', 'bbloomer_add_cc_to_emails', 9999, 3);

function bbloomer_add_cc_to_emails($headers, $email_id, $order) {
    if (is_a($order, 'WC_Order')) {
        $cc = $order->get_meta('_cc_email_address');
        if (!empty($cc)) {
            $headers .= 'Cc: ' . $cc . "\r\n";
        }
    }
    return $headers;
}

Wrapping Up

With just a few snippets, you’ve enhanced your WooCommerce checkout with an optional feature that allows customers to add a second recipient for their order emails. This small UX upgrade can make a big difference, especially for business clients who need to loop in multiple stakeholders.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *