Category Archives: woocommerce

woocommerce – only sell to specific cities



add_filter( 'woocommerce_form_field_args', 'custom_form_field_args', 10, 3 );
            function custom_form_field_args( $args, $key, $value ) { 
                if ( $args['id'] == 'billing_city' ) {
                 $args = array(
                        'label' => __( 'Town / City', 'woocommerce' ),
                        'required' => TRUE,
                        'clear' => TRUE,
                        'type' => 'select',
                        'options' =>  array(
                            '' => ('Select City' ),
                    'Bangalore' => ('Bangalore' ),
                    'Mysore' => ('Mysore' )
                    ),
                        'class' => array( 'update_totals_on_change' )
                    );
                } // elseif … and go on 

                return $args;
            };

And


function wc_sell_only_states( $states ) {
	$states['BR'] = array(
		'MG' => __( 'Minas Gerais', 'woocommerce' ),
	);

	return $states;
}
add_filter( 'woocommerce_states', 'wc_sell_only_states' );

As seen on