• Resolved loopforever

    (@loopforever)


    Hi,
    First of all, thank you for the plugin. It’s very functional and really works.

    I defined a new dropdown on the checkout page, just like state:
    shipping_district
    billing_district
    I’m trying to include this data in your plugin.
    I reviewed the scripts.min.js and scripts.js files and made additions according to my needs. But I couldn’t do the other side. I’m making a new definition using the wc_address_book_address_select_label filter, but the select option data is not coming in on the checkout page. Can you guide me?

    Briefly, how can I include a new field? Do you have a development example?
    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Matt Harrison

    (@matt-h-1)

    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.

    Thread Starter loopforever

    (@loopforever)

    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 3 years, 1 month ago by loopforever.
    • This reply was modified 3 years, 1 month ago by loopforever.
    Plugin Author Matt Harrison

    (@matt-h-1)

    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

    Thread Starter loopforever

    (@loopforever)

    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 3 years, 1 month ago by loopforever.
    Thread Starter loopforever

    (@loopforever)

    I just saw your message, I’ll add according to the edit. Thank you.

    Thread Starter loopforever

    (@loopforever)

    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 3 years, 1 month ago by loopforever.
    • This reply was modified 3 years, 1 month ago by loopforever.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Defining a New Field’ is closed to new replies.