Skip to content

Instantly share code, notes, and snippets.

@tavomak
Last active July 13, 2017 21:07
Show Gist options
  • Save tavomak/1d118f311f17c394efefb42a004b36f7 to your computer and use it in GitHub Desktop.
Save tavomak/1d118f311f17c394efefb42a004b36f7 to your computer and use it in GitHub Desktop.
Campos de ciudad y agencia
<?php
function custom_city_field( $city_fields ) {
//Obtiene el estado seleccionado
$estado_actual = WC()->customer->get_shipping_state();
/* De requerirse esta devuelve la ciudad
$agency = WC()->customer->get_shipping_city();*/
//Se generan los array que contienen los datos a mostrar en los select box
$estado['DC'] = array(
'CARACAS' => array(
'ZOOM C.C. GALERIAS EL PARAISO',
'ZOOM TAQUILLA DIA DIA UNICENTRO EL MARQUES',
'ZOOM TAQUILLA MAKRO LA YAGUARA'
)
);
$estado['LA'] = array(
'BARQUSIMETO' => array(
'ZOOM BARQUISIMETO',
'ZOOM AEROPUERTO JACINTO LARA',
'ALIADO ZOOM EXIMCOM 101, C.A'
),
'CABUDARE' => array(
'ZOOM CABUDARE'
),
'CARORA' => array(
'ZOOM CARORA'
),
'EL TOCUYO' => array(
'ALIADO ZOOM DISTRIBUIDORA DEL SUR 83, C.A.'
)
);
//variables vacias para guardar como arrat los resultados de las iteraciones
$datos = array();
$datos1 = array();
$datos2 = array();
$datos3 = array();
foreach( $estado["estado_actual"] as $ciudad => $agencia ){
$datos[] = $ciudad;
foreach ($estado["estado_actual"][$ciudad] as $name => $key){
$datos1[] = $name;
}
foreach ($agencia as $nombre=>$direccion){
$datos2[] = $nombre;
$datos3[] = $direccion;
}
}
//Se generan el select ciudad
if ( !empty( $estados ) ) {
$city_fields['shipping']['shipping_city'] = array(
'type' => 'select',
'options' => $datos,//Opciones en el array generado
'label' => 'Ciudad',
'placeholder' => 'Ciudad',
'required' => true,
'class' => array("cb")
);
}
//Se genera el select agencia
if ( !empty( $datos ) ) {
$city_fields['shipping']['shipping_agency'] = array(
'type' => 'select',
'options' => $datos1[0],//Opciones en el array generado
'label' => __("Agencia Zoom $estados", 'woocommerce'),
'required' => true,
'class' => array("store-pickup form-row-wide $agency ")
);
}
return $city_fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_city_field');
?>
<div class="shipping_address">
<p class="form-row form-row form-row-first validate-required" id="shipping_first_name_field">
<label for="shipping_first_name" class="">Nombre <abbr class="required" title="obligatorio">*</abbr>
</label>
<input type="text" class="input-text " name="shipping_first_name" id="shipping_first_name" placeholder="" autocomplete="given-name" value="">
</p>
<p class="form-row form-row form-row-last validate-required" id="shipping_last_name_field">
<label for="shipping_last_name" class="">Apellido <abbr class="required" title="obligatorio">*</abbr>
</label><input type="text" class="input-text " name="shipping_last_name" id="shipping_last_name" placeholder="" autocomplete="family-name" value="">
</p>
<div class="clear"></div>
<p class="form-row form-row form-row-first address-field validate-required validate-state" id="shipping_state_field">
<label for="shipping_state" class="">Estado <abbr class="required" title="obligatorio">*</abbr>
</label>
<div class="select2-container state_select" id="s2id_shipping_state">
<a href="javascript:void(0)" class="select2-choice" tabindex="-1">
<span class="select2-chosen" id="select2-chosen-2">Lara</span>
<abbr class="select2-search-choice-close"></abbr>
<span class="select2-arrow" role="presentation"><b role="presentation"></b></span>
</a>
<label for="s2id_autogen2" class="select2-offscreen">Estado *</label>
<input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-2" id="s2id_autogen2">
<div class="select2-drop select2-display-none select2-with-searchbox">
<div class="select2-search">
<label for="s2id_autogen2_search" class="select2-offscreen">Estado *</label>
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" role="combobox" aria-expanded="true" aria-autocomplete="list" aria-owns="select2-results-2" id="s2id_autogen2_search" placeholder="">
</div>
<ul class="select2-results" role="listbox" id="select2-results-2">
</ul>
</div>
</div>
<select name="shipping_state" id="shipping_state" class="state_select " data-placeholder="Estado" autocomplete="address-level1" tabindex="-1" title="Estado *" >
<option value="">Elige un estado/província…</option>
<option value="AM">Amazonas</option>
<option value="AN">Anzoátegui</option>
<option value="AP">Apure</option>
<option value="AR">Aragua</option>
<option value="BA">Barinas</option>
<option value="CA">Carabobo</option>
<option value="CO">Cojedes</option>
<option value="DA">Delta Amacuro</option>
<option value="DC">Distrito Capital</option>
<option value="FA">Falcón</option>
<option value="GU">Guárico</option>
<option value="LA" selected="selected">Lara</option>
<option value="ME">Mérida</option>
<option value="MI">Miranda</option>
<option value="MO">Monagas</option>
<option value="NE">Nueva Esparta</option>
<option value="PO">Portuguesa</option>
<option value="SU">Sucre</option>
<option value="TA">Táchira</option>
<option value="TR">Trujillo</option>
<option value="VA">Vargas</option>
<option value="YA">Yaracuy</option>
<option value="ZU">Zulia</option>
</select>
</p>
<!--CAMPO PARA CIUDAD GENERADO EN CHECKOUT.PHP"DEBE DEPENDER DEL ESTADO SELECIONADO"-->
<p class="form-row form-row cb validate-required" id="shipping_city_field">
<label for="shipping_city" class="">Ciudad <abbr class="required" title="obligatorio">*</abbr>
</label>
<select name="shipping_city" id="shipping_city" class="select " data-placeholder="Ciudad">
<option value="0">BARQUSIMETO</option>
<option value="1">CABUDARE</option>
<option value="2">CARORA</option>
<option value="3">EL TOCUYO</option>
</select>
</p>
<!--CAMPO PARA AGENCIA GENERADO EN CHECKOUT.PHP "DEBE DEPENDER DE LA CIUDAD SELECCIONADA"-->
<p class="form-row form-row store-pickup form-row-wide 0 validate-required" id="shipping_agency_field">
<label for="shipping_agency" class="">Agencia Zoom LA <abbr class="required" title="obligatorio">*</abbr>
</label>
<select name="shipping_agency" id="shipping_agency" class="select " data-placeholder="">
<option value="0">ZOOM BARQUISIMETO</option>
<option value="1">ZOOM AEROPUERTO JACINTO LARA</option>
<option value="2">ALIADO ZOOM EXIMCOM 101, C.A</option>
</select>
</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment