skip to Main Content

I need that when a customer fill _billing_adress in Woocommerce… this value will be the same that _billing_address_2. If is possible with any function?

add_action('woocommerce_payment_complete', 'replicate_billing_adress', 100, 1);

function replicate_billing_adress($order_id){
    $order = new WC_Order($order_id); //obatin the completed order as object
    $_billing_address_1 = $order->_billing_address_1(); //get the billing email address
    update_post_meta($order_id, '_billing_address_1', $_billing_address_2); //update the company email
    update_post_meta($order_id, '_billing_address_1', $_billing_address_2); //it maybe saved like that, with underscore, ommit if not needed
}

3

Answers


  1. Chosen as BEST ANSWER

    yes it´s just an example but I don´t know if it will be...

    add_action('woocommerce_payment_complete', 'replicate_billing_adress', 100, 1);
    
    function replicate_billing_adress($order_id){ 
        $order = new WC_Order($order_id);  
    $_billing_address_1 = $order->_billing_address_1(); 
    update_post_meta($order_id, '_billing_address_1', $_billing_address_2); /
        update_post_meta($order_id, '_billing_address_1', $_billing_address_2); 
    $order->update_meta_data('_billing_address_2', $_billing_address_1);
    $order->save_meta_data();
    }
    

    I don´t understand your code.


  2. $order->update_meta_data('_billing_address_2', $_billing_address_1);
    $order->save_meta_data();
    
    Login or Signup to reply.
  3. Check this out

    add_action('woocommerce_thankyou', 'replicate_billing_adress', 10, 1); 
    // Update billing address 2
    function replicate_billing_adress($order_id){
         $order = wc_get_order($order_id);
         $_billing_address_1 = $order->_billing_address_1();
         $order->update_meta_data('_billing_address_2', $_billing_address_1);
         $order->save_meta_data();
    }
    
    add_action( 'woocommerce_admin_order_data_after_order_details', 'display_billing_address_2_in_admin' );
    
    // display the extra data in the order admin panel
    function display_billing_address_2_in_admin( $order ){  ?>
        <div class="order_data_column">
            <h4><?php _e( 'Billing address 2', 'woocommerce' ); ?></h4>
            <?php echo '<p><strong>' . __( 'Billing Address 2' ) . ':</strong>' . $order->get_meta( '_billing_address_2' ) . '</p>'; ?>
        </div>
    <?php }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search