Created
March 1, 2015 20:44
-
-
Save full-stack-king/367cae83644c3961a06d to your computer and use it in GitHub Desktop.
Here is a quick snippet to display WooCommerce product custom meta fields values (place it in functions.php):
This file contains 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 | |
/** | |
* WooCommerce Extra Feature | |
* -------------------------- | |
* | |
* Display product meta field in a shortcode | |
* ex: [woo_custom_field id="my-custom-field"] | |
* | |
*/ | |
function woo_custom_field_shortcode( $atts, $content = null ) { | |
global $post; | |
extract(shortcode_atts(array( | |
"id" => '' | |
), $atts)); | |
$fields = get_post_meta( $post->ID, $id); | |
foreach( $fields as $field ) { | |
return $field; | |
} | |
} | |
add_shortcode("woo_custom_field", "woo_custom_field_shortcode"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment