Skip to content

Instantly share code, notes, and snippets.

@mix5003
Last active March 14, 2017 02:36
Show Gist options
  • Select an option

  • Save mix5003/1f85c573c0ad1994796ee759f4b81b18 to your computer and use it in GitHub Desktop.

Select an option

Save mix5003/1f85c573c0ad1994796ee759f4b81b18 to your computer and use it in GitHub Desktop.
May be add virtual field to access state name in woocommerce
  1. add new code to functions.php
  2. use billing_state_readable instead of billing_state
<?php
function add_readable_metakey( $value, $object_id, $meta_key, $single ) {
// Maybe modify $example in some way.
if($meta_key == 'billing_state_readable'){
$country = get_post_meta( $object_id, '_billing_country', true );
$state = get_post_meta( $object_id, '_billing_state', true );
return WC()->countries->states[$country][$state];
}
if($meta_key == 'shipping_state_readable'){
$country = get_post_meta( $object_id, '_shipping_country', true );
$state = get_post_meta( $object_id, '_shipping_state', true );
return WC()->countries->states[$country][$state];
}
return $value;
}
add_filter( 'get_post_metadata', 'add_readable_metakey' ,10 ,4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment