WooCommerce Duplicate Billing to Shipping Address For Virtual Products

With WooCommerce if a customer orders a virtual product there is no shipping address displayed on the checkout page.  This makes sense as there is no physical item being posted to your customer.  However, a few of my clients like to have the WooCommerce billing address match the shipping address.  Subsequently, I wrote this piece of code to place in your functions.php file that will duplicate the billing to shipping address for orders containing a virtual product in WooCommerce.

The function will fire when a new customer is created on the placing of an order in WooCommerce.

 

3 thoughts on “WooCommerce Duplicate Billing to Shipping Address For Virtual Products

  1. Sorry, tried removing virtual products code but it’s not copying shipping to billing. Here’s what I did:

    add_action( 'woocommerce_created_customer', 'es_insert_member_shipping_meta' );

    function es_insert_member_shipping_meta( $user_id )
    {
    global $woocommerce;

    // Loop through cart products
    foreach( $products as $product ) {

    //Update all the shipping values, Address line 2 and Company Name is the only field not mandatory
    update_user_meta( $user_id, 'shipping_country', esc_attr($woocommerce->customer->get_country()));
    update_user_meta( $user_id, 'shipping_first_name', get_user_meta($user_id, 'first_name', true));
    update_user_meta( $user_id, 'shipping_last_name', get_user_meta($user_id, 'last_name', true));
    if ($billing_company)
    update_user_meta( $user_id, 'shipping_company', esc_attr());
    update_user_meta( $user_id, 'shipping_address_1', esc_attr($woocommerce->customer->get_address()));
    if($address_line_2)
    update_user_meta( $user_id, 'shipping_address_2', esc_attr($woocommerce->customer->get_address_2()));
    update_user_meta( $user_id, 'shipping_city', esc_attr($woocommerce->customer->get_city()));
    update_user_meta( $user_id, 'shipping_state', esc_attr($woocommerce->customer->get_state()));
    update_user_meta( $user_id, 'shipping_postcode', esc_attr($woocommerce->customer->get_postcode()));
    }
    }

  2. Nope.. Sorry. Still doesn’t work. Please email me if you have time for this small project. Thank you!

Leave a Reply

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