Skip to content

Instantly share code, notes, and snippets.

@yward
Forked from Preciousomonze/wc_pv_custom_filters.php
Created August 12, 2020 00:43
Show Gist options
  • Save yward/5e0cdbced20492f73c6384d785b0cf2d to your computer and use it in GitHub Desktop.
Save yward/5e0cdbced20492f73c6384d785b0cf2d to your computer and use it in GitHub Desktop.
Phone Validator Custom Filters and How to Use πŸ“
/**
* List of Phone Validator for WooCommerce custom Filters and how to use.
*
* Please feel free to add more to this, and don't forget to add your name to contributors, if you want to.
*
* @author Precious Omonzejele (CodeXplorer πŸ€ΎπŸ½β€β™‚οΈπŸ₯žπŸ¦œπŸ€‘)
* @contributors ...add name(s) here
*/
/**
* Separate dial code
*
* @since 1.2.0
* @return bool
*/
add_filter( 'wc_pv_separate_dial_code', '__return_true' );
/**
* Set Default Country
*
* Incase you do not want to use the WooCommerce store country as default
*
* @param string $value the country's abbr e.g NG for Nigeria
* @since 1.2.0
* @return bool
*/
function pekky_cx_default_country( $value ){
$value = 'es'; // Nigeria πŸ‡³πŸ‡¬
return $value;
}
add_filter( 'wc_pv_set_default_country', 'pekky_cx_default_country' );
/**
* Use your WooCommerce store country as default
*
* @since 1.2.0
* @return bool
*/
add_filter( 'wc_pv_use_wc_default_store_country', '__return_true' );
/**
* Allowed countries
*
* @param array $countries initials
* @since 1.2.0
* @return array
*/
function pekky_cx_allowed_countries( $countries ){
$countries = array('Ng','gh');
// Or add to allowed countries
// $countries[] = 'ng'; πŸ’†πŸ½β€β™‚οΈπŸ¦œ
return $countries;
}
add_filter( 'wc_pv_allowed_countries', 'pekky_cx_allowed_countries' );
/**
* Preferred countries
*
* @param array $countries initials
* @since 1.3.0
* @return array
*/
function pekky_cx_preferred_countries( $countries ){
$countries = array('ng','gh','es');
return $countries;
}
add_filter( 'wc_pv_preferred_countries', 'pekky_cx_preferred_countries' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment