Support » Plugin: WooCommerce » Regions as Countries and Districts as Regions

  • Resolved Samir Rifai

    (@srifaia)


    I’ve managed to create new Regions as if they were Countries, and Districts as if they were Regions.

    In General settings tab everything looks great. However, the shipping tab is not showing the new Regions created.

    How can I show the newly created Regions in the Shipping tab settings?

    <?php
    
    // Add a new country to countries list
    
    add_filter( 'woocommerce_countries',  'new_add_my_country' );
    function new_add_my_country( $countries ) {
      $new_countries = array(
    	                    'LIMM'  => __( 'Lima (Metropolitana)', 'woocommerce' ),
    	 					'LIMP'  => __( 'Lima (Provincia)', 'woocommerce' ),
    	  					'CALL'  => __( 'Callao', 'woocommerce' ),
    	                    );
    
    	return array_merge( $countries, $new_countries );
    }
    
    // Add this to your theme's functions.php file. Replace XX with the country code
    
    add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
     
    function custom_woocommerce_states( $states ) {
     
        $states['LIMM'] = array(
                'LIMM1' => __('Ancón', 'woocommerce') ,
                'LIMM2' => __('Barranco', 'woocommerce') ,
                'LIMM3' => __('Santiago de Surco', 'woocommerce')
        );
    
        return $states;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter Samir Rifai

    (@srifaia)

    Hi thanks for your reply.

    I’ve resolved the issue adding the following code:

    add_filter( 'woocommerce_continents', 'new_add_my_country_to_continents' );
    function new_add_my_country_to_continents( $continents ) {
    	$continents['PERU']['countries'][] = 'LIMM';
    	$continents['PERU']['countries'][] = 'CALL';
    	return $continents;
    }

    Now the new Regions and Districts are shown in the native Shipping settings.

    Plugin Support Mike Straw

    (@mikestraw)

    Hi @srifaia ,

    Glad to hear it – thanks for letting us know!

    I’ll mark this thread as resolved now. If you have any further questions, I recommend creating a new thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Regions as Countries and Districts as Regions’ is closed to new replies.