• Resolved afuz2020

    (@afuz2020)


    I am currently encountering some issues as regards shipping regions for woocommerce on an online store I am working on. Its well established that Woocommerce core only has provisions for states or provinces within a country. I have been trying to breakdown these states to cities and districts. I got to a stage with a code, but the districts for the capital of my country, Abuja, are displaying as states under Nigeria, and not as districts under the capital in the dropdown of shipping regions under Nigeria. I am seeking assistance on how to tweak the code to make the the districts and cities of states and Abuja, to be under their various states and not as a standalone state under Nigeria. Keen for the newly added districts to appear under their respective states at the Cart/checkout pages, and as additional state as its currently showing
    Please, find the below more details from screenshot links and the code I used

    https://tinyurl.com/yy94ufgt (Four of Nigeria’s 36 states on woocommerce core)
    https://tinyurl.com/yxtwywmk (the places I added that are appearing as states that I want as districts under the Capital, Abuja)
    https://tinyurl.com/y3a324f3 (the code snippet)

    The code I used is this

    add_filter( ‘woocommerce_states’, ‘adding_custom_country_states’ );
    function adding_custom_country_states( $states ) {

    // Define the related country code
    $country_code = ‘NG’;

    // Define for each state a different state code
    $new_states = array(
    ‘FC1’ => __(‘Wuse’, ‘woocommerce’),
    ‘FC2’ => __(‘Maitama’, ‘woocommerce’),
    ‘FC3’ => __(‘Wuye’, ‘woocommerce’),
    ‘FC4’ => __(‘Asokoro’, ‘woocommerce’),
    );

    // Merge existing states with the new states
    $states[$country_code] += $new_states;

    return $states;

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Hi there,

    There’s no builtin support within Woo that you can sue to add sub-field to the state field, so it will most likely require some more code to add fields with this method https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ and then show those fields and sign the district/city value conditionally with jQuery.

    Thread Starter afuz2020

    (@afuz2020)

    @corsonr thank you for your reply and insight on this. But I don’t think this exactly answers the question I raised? The page you pointed me to, has to do with the checkout page. I would appreciate if you could guide me still to a practical case scenario of tweaking the exact code from the page attached. Because I am new to this, and this has left me rather confused.

    Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Unless I missed something you didn’t mention on which page the changes should occur, that’s why I assumed it was on the checkout page since it’s most likely the states field appears. Can you please be more specific?

    Thread Starter afuz2020

    (@afuz2020)

    @corsonr Okay

    The area I am looking to tweak is the shipping regions under shipping zones. Under Nigeria in the Woocommerce core shipping regions, there are 36 states and the federal capital, Abuja. making it 37. I added some cities/districts under Abuja, these cities/districts are appearing as additional states under the shipping region of Nigeria, bringing the number to 41, and not as districts under the capital ,Abuja. So I want these districts to be under Abuja, and not as additional states under Nigeria.
    I want to set shipping fees for each of these districts under Abuja, since they are appearing as additional states and not districts, it makes it difficult.
    I want a situation when a person indicate their district within the capital, it displays as such, e. g. (District, State, Country, – Wuse, Abuja, Nigeria)
    https://tinyurl.com/yxtwywmk (the districts I added that are appearing as states under Nigeria, that I want as districts under the Capital, Abuja)

    • This reply was modified 4 years, 5 months ago by afuz2020.
    • This reply was modified 4 years, 5 months ago by afuz2020.
    • This reply was modified 4 years, 5 months ago by afuz2020.
    Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    Oh you’re talking about the dashboard, not the frontend? That makes sense now.

    Wow, that’s another story! This would require quite a lot of custom coding, which I won’t be able to provide, unfortunately. Maybe you should consider hiring a dev to do that.

    Thread Starter afuz2020

    (@afuz2020)

    @corsonr Thank You for your response.

    Remi Corson

    (@corsonr)

    Automattic Happiness Engineer

    You’re very welcome.

    Now, I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Newly added districts on Woocommerce Shipping appears as new states not district’ is closed to new replies.