- add new code to functions.php
- use
billing_state_readableinstead ofbilling_state
Last active
March 14, 2017 02:36
-
-
Save mix5003/1f85c573c0ad1994796ee759f4b81b18 to your computer and use it in GitHub Desktop.
May be add virtual field to access state name in woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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