• Resolved Alex Musial

    (@bigaltheking)


    I have added a custom field “shipping_address_nickname_identifier”

    I can create a 2nd shipping address, and then I correctly end up with
    “shipping_address_nickname_identifier” & “shipping2_address_nickname_identifier”. When I make the 2nd address primary, the custom field does not get updated.

    What would prevent this from working?

    • This topic was modified 9 months, 3 weeks ago by Alex Musial.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Matt Harrison

    (@matt-h-1)

    How are you adding the custom field? If your custom code or the plugin you are using uses the 'woocommerce_billing_fields' or 'woocommerce_shipping_fields' filters to add the custom field to the WooCommerce Address fields then the plugin should handle managing that field in the address automatically for saving and updating addresses.

    Thread Starter Alex Musial

    (@bigaltheking)

    Hi Matt,

    I have added the field with the following:

    add_filter( ‘woocommerce_shipping_fields’, ‘misha_add_shipping_field’ );
    function misha_add_shipping_field( $fields ) {
    $fields[‘shipping_address_nickname_identifier’] = array(
    ‘label’ => ‘shipping_address_nickname_identifier’,
    ‘required’ => false,
    ‘class’ => array( ‘form-row-wide’, ‘my-custom-class’ ),
    ‘priority’ => -2,
    ‘placeholder’ => ‘shipping identifier’,
    );

    return $fields;

    }

    Plugin Author Matt Harrison

    (@matt-h-1)

    Hmm, that should work just fine. That is the same way we add the “Address nickname” field to the addresses in the plugin.

    Thread Starter Alex Musial

    (@bigaltheking)

    ok, it started working after renaming function, appreciate your time.

    Thread Starter Alex Musial

    (@bigaltheking)

    Do you know if Make Primary will call the Hook: woocommerce_after_save_address_validation.

    Plugin Author Matt Harrison

    (@matt-h-1)

    It does not call that hook. No field validation is performed at that step since it is only swapping the addresses.

    Addresses would have already been validated before saving the first time.

    Thread Starter Alex Musial

    (@bigaltheking)

    is there another hook or a way i can trigger a function upon make primary?

    Plugin Author Matt Harrison

    (@matt-h-1)

    add_action( 'wp_ajax_wc_address_book_make_primary', 'your_function_name', 9 );

    Is probably closest with the current code. That would trigger before the address swapping.

    But we can add a new hook that is called after the swap happens in a future version of the plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Field not being copied with Make Primary button’ is closed to new replies.