Skip to content

Instantly share code, notes, and snippets.

@full-stack-king
Created March 1, 2015 20:44
Show Gist options
  • Save full-stack-king/367cae83644c3961a06d to your computer and use it in GitHub Desktop.
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):
<?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