Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.