Hi,
Are you using the latest version of the plugin? The last version had some fixes for Dropdown/select fields.
You shouldn’t need to edit the javascript at all for adding a new custom field.
I’m assuming you added the custom fields using the standard WooCommerce method? https://woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-6
The wc_address_book_address_select_label filter is just to customize the preview name in the Address Book dropdown, it doesn’t affect what fields are filled at all.
Thank you for your answer.
Yes I am using the latest version.
Unfortunately, I still haven’t been able to resolve this issue. Actually I added a plugin new domain: Link
This plugin basically does the following, although the example is not very accurate:
Matches the selected state with the district. That is, districts are loaded according to the selected state. For example, if we consider for the USA
California –> Sacramento
California –> Los Angeles
I also checked this plugin. As you said, I did not see a problem with adding Woocommerce hooks. But if necessary, I will write again myself.
Actually the only problem on your part is data mapping. If a new address is added, it will appear in My Account > My Addresses. There is no problem here. However, the newly added data value is not loaded on the checkout page. That is, if the customer chooses the address it added from the address book, no value is passed to the dropdown.
You said that there is no need to edit in terms of Javascript. However, there is an element with a new ID. Probably the data is not transferred because of this. I could not understand exactly what you are saying. Isn’t it necessary to write js for the new element to transfer data?
-
This reply was modified 4 years, 4 months ago by
loopforever.
-
This reply was modified 4 years, 4 months ago by
loopforever.
Ahh, in that case, yes you would need custom javascript since it sounds like it is loading the District options dynamically based on which State is selected.
By default the Address Book plugin will try to set the dropdown with the saved value from the address but if the dropdown field is not populated with options yet then it will be unable to set it. So that part should be delayed until after the dropdown field is populated with options.
Feel free to share your changes to scripts.js
I simplified the project and translated it into English. Could you please examine it?
Main File: Online Editor
And other files:
Online File-2
Online File-3
Online File-4
Online File-5
-
This reply was modified 4 years, 4 months ago by
loopforever.
I just saw your message, I’ll add according to the edit. Thank you.
Hi again,
I solved the problem with a little JS code. As far as I can see, the new field is overwritten by the plugin. So, the new field is written on Shipping City. However, the Shipping City field is running in the background and the data is transferred with your plugin (from the address book).
I also wrote a jquery code that is triggered based on the field change in the past. Data received from Shipping City is transferred to the new field.
Maybe it will help someone else, below is the code.
I added the code with the woocommerce_before_order_notes hook as I have other works.
add_action ('woocommerce_before_order_notes', 'address_book_js_code_define_on_checkout_page' );
function address_book_js_code_define_on_checkout_page () {?>
<script type="text/javascript">
jQuery(document).ready(function($){
jQuery("#shipping_city").change(function(){
jQuery("[name='shipping_district']").val(jQuery("[name='shipping_city']").val()).change();
});
});
</script>
<?php
}
-
This reply was modified 4 years, 4 months ago by
loopforever.
-
This reply was modified 4 years, 4 months ago by
loopforever.