Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Oscar-Abad-Folgueira/02ee1d2c6a7177fe5bb989df23dcf9b2 to your computer and use it in GitHub Desktop.
Save Oscar-Abad-Folgueira/02ee1d2c6a7177fe5bb989df23dcf9b2 to your computer and use it in GitHub Desktop.
Convertir el campo de código postal del checkout de WooCommerce en un campo tipo select con los códigos postable válidos
<?php
/**
* @author Oscar Abad Folgueira
* @author_url https://www.oscarabadfolgueira.com
* @snippet_url https://www.oscarabadfolgueira.com/convertir-el-campo-de-codigo-postal-de-woocommerce-en-un-select-o-lista-deplegable/
* @description Convertir el campo de código postal del checkout de WooCommerce en un campo tipo select con los códigos postable válidos.
*/
add_filter( 'woocommerce_default_address_fields' , 'customize_postcode_fields' );
function customize_postcode_fields( $adresses_fields ) {
$adresses_fields['postcode']['type'] = 'select';
$adresses_fields['postcode']['validate'] = false; // desactivar la validación del código postal
$adresses_fields['postcode']['required'] = true;
$adresses_fields['postcode']['options'] = array(
'' => __('Selecciona tu código postal', 'woocommerce'),
'option_1' => '01470', // lista de códigos postales
'option_2' => '01473', // Añadir los que necesitemos
'option_3' => '01476'
);
return $adresses_fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment