• Resolved jonesej

    (@jonesej)


    I have added the woocommerce billing fields to my registration form using the function and hook below:

    function my_custom_function(){
    global $woocommerce;
    $checkout = $woocommerce->checkout();

    foreach ($checkout->checkout_fields[‘billing’] as $key => $field) :
    if(!($key == ‘billing_first_name’ || $key == ‘billing_last_name’)){
    $field[‘required’] = false;
    }
    if(!($key == ‘billing_email’)){
    woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
    }
    endforeach;
    }
    add_action(‘woocommerce_register_form’,’my_custom_function’);

    the issue i have is the state is not updating when the country dropdown selection is changed. I assume there is JS i need to hook to the onchange event but i can’t find documentation on what that is. Can someone please help point me in the right direction without having to rebuild them all myself?

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Thread Starter jonesej

    (@jonesej)

    @mike Jolley
    Thank you for your response that was exactly what I needed and it is now working as expected. In the end, I added to following code to my customized form-login.php template file:

    <?php
      $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
      $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/';
      $frontend_script_path = $assets_path . 'js/frontend/';
    
      wp_enqueue_script( 'wc-country-select', $frontend_script_path . 'country-select' . $suffix . '.js' );
    ?>

    I hope that was an accurate solution.

    Hello Mike and Jonesej,

    I tried to enqueue script for custom template, working very well.
    But i wanted to do some minor modifications to script(country-select) which will be only for custom template, at the same time i don’t want to touch any of woocommerce scripts.
    Any suggestion?

    Thanks,
    Sam

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Billing Fields Added to Registration Form – State Not Updating’ is closed to new replies.