Skip to content

Instantly share code, notes, and snippets.

@KeylorCR
Last active March 15, 2022 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeylorCR/9cf298867b3a6539f00f1c0b0b204001 to your computer and use it in GitHub Desktop.
Save KeylorCR/9cf298867b3a6539f00f1c0b0b204001 to your computer and use it in GitHub Desktop.
Custom filters and functions for plugin WC Provincia-Cantón-Distrito
<?php
/**
* Adding custom json locations from child theme
* WC Provincia-Canton-Distrito
*/
function kmchild_prov_cant_dist_json($json_file) {
$json_file = get_stylesheet_directory_uri() . '/assets/js/prov-cant-dist.json';
return $json_file;
}
add_filter('wcpcd_prov_cant_dist_json', 'kmchild_prov_cant_dist_json');
/**
* State filter
* WC Provincia-Canton-Distrito
*/
function kmchild_state_field_label($label) {
return __('Estado', 'textdomain');
}
add_filter('wcpcd_state_field_label', 'kmchild_state_field_label');
/**
* City filter
* WC Provincia-Canton-Distrito
*/
function kmchild_city_field_label($label) {
return __('Ciudad', 'textdomain');
}
add_filter('wcpcd_city_field_label', 'kmchild_city_field_label');
/**
* Dropdown city placeholder filter
* WC Provincia-Canton-Distrito
*/
function kmchild_city_field_placeholder($placeholder) {
return __('Seleccione un cantón-distrito', 'textdomain');
}
add_filter('wcpcd_city_field_placeholder', 'kmchild_city_field_placeholder');
/**
* Address fields order for Provincia-Canton-Distrito
* WC Provincia-Canton-Distrito
*/
function kmchild_address_fields( $fields ) {
$fields['state']['priority'] = 42;
$fields['city']['priority'] = 43;
$fields['address_1']['priority'] = 44;
return $fields;
}
add_filter('woocommerce_default_address_fields', 'kmchild_address_fields', 80);
/**
* Adding an empty state by country
*/
function kmchild_wc_states( $states ) {
$states['RO'] = array_merge( array( 'A' => __( 'Choose a state', 'your-textdomain' ) ), $states['RO'] );
return $states;
}
add_filter( 'woocommerce_states', 'kmchild_wc_states' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment