Here's the metabox code what I'm using which is working fine for me:
// Add meta boxes with TinyMCE via wp_editor() function
// Define the custom box
add_action( 'add_meta_boxes', 'product_details_add' );
// Do something with the data entered
add_action( 'save_post', 'product_details_save' );
// Adds a box to the main column on the Product post_type edit screens
function product_details_add() {
add_meta_box( 'product_details', 'Product Details', 'product_details_call', 'product', 'normal', 'high' );
}
// Prints the box content
function product_details_call( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'product_details_noncename' );
$field_value = get_post_meta( $post->ID, 'product_details_meta', false );
wp_editor( $field_value[0], 'product_details_meta' );
}
// When the post is saved, saves our custom data
function product_details_save( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['product_details_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['product_details_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['product_details_meta'] ) ) {
update_post_meta( $post_id, 'product_details_meta', $_POST['product_details_meta'] );
}
}
////////////
However, get_post_meta()
is not returning the data in my template pages so I'm using a more "direct" method to get show the meta content:
<?php echo $product->product_custom_fields['product_details_meta'][0];?>
Of course this assumes that you also declare global $product;
somewhere above this code in your template file.