WordPress.org

Forums

WooCommerce - excelling eCommerce
Limit by cities. (2 posts)

  1. q-styler
    Member
    Posted 1 year ago #

    Hi!
    I'm trying to set up a WooCommerce to work in only two cities.
    How can I change a city input in address form from text to drop down menu showing only two cities?

    Thank you!

    http://wordpress.org/extend/plugins/woocommerce/

  2. oscareyes07
    Member
    Posted 1 year ago #

    Hi q-styler.

    Sorry for my english

    I has the same trouble, you can solve this in this way:

    - First Remove the City input box from the form

    add_filter( 'woocommerce_checkout_fields' , 'override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function override_checkout_fields( $fields ) {
         unset($fields['billing']['billing_city']);
         unset($fields['shipping']['shipping_city']);
         return $fields;
    }

    - Second, make your own box with options

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
         $fields['billing']['billing_ciudad']= array(
        'type' => 'select',
        'label'     => __('Ciudad', 'woocommerce'),
        'placeholder'   => _x('San Salvador', 'placeholder', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
         );
         $fields['billing']['billing_ciudad']['options'] = array(
         	'option_1' => 'Col. Escalon',
      		'option_2' => 'Otro ciudad o colonia'
         	);
         return $fields;
    }

    You can see more on documentation:

    Here

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.