• Resolved Alex Musial

    (@bigaltheking)


    I am trying to identify the shipping address metakey, if it is shipping_ or shipping2_ when using the ‘woocommerce_after_save_address_validation’.

    What I need to do, is update a new hidden field with the corresponding entry of shipping_ or shipping2_ ect……

    When using hook ‘woocommerce_after_save_address_validation’ how can I identify which address is being saved?

    Thanks,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Alex Musial

    (@bigaltheking)

    I was able to get it off the ?address-book=shipping2

    thnx

    Plugin Author Matt Harrison

    (@matt-h-1)

    Hi Alex,

    Good to hear that you were able to find it, yes the query string is the way to get it if you are using that hook.

    This code is the code we use in the plugin to grab the name:

    $address_book_name = sanitize_text_field( wp_unslash( $_GET['address-book'] ) );

    If you are doing a large modification to the plugin then you might want to look at our development version at https://github.com/crosspeaksoftware/woo-address-book/ which contains the code that will be the 3.x version of the plugin. It is in a working state at the moment. We have changed the data structure there and no longer rename the fields with shipping2_ and shipping3_ etc.

    With the new version you can use the plugin code to update an address with something like:

    $address_book_name = sanitize_text_field( wp_unslash( $_GET['address-book'] ) );
    $customer = new WC_Customer( get_current_user_id() );
    $address = WC_Address_Book::get_instance()->get_address( $customer, $address_book_name, 'shipping' );
    // Do something with $address array.
    WC_Address_Book::get_instance()->save_address( $customer, $address_book_name, 'shipping', $address );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to identify the shipping address’ is closed to new replies.