Skip to content

Instantly share code, notes, and snippets.

  • Star 9 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bhwebworks/df6b827586addede3403 to your computer and use it in GitHub Desktop.
Add custom metaboxes to WooCommerce products
/**
* Create Custom Meta Boxes for WooCommerce Product CPT
*
* Using Custom Metaboxes and Fields for WordPress library from
* Andrew Norcross, Jared Atchinson, and Bill Erickson
*
* @link http://blackhillswebworks.com/?p=5453
* @link https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress
*/
add_filter( 'cmb_meta_boxes', 'bhww_core_cpt_metaboxes' );
function bhww_core_cpt_metaboxes( $meta_boxes ) {
//global $prefix;
$prefix = '_bhww_'; // Prefix for all fields
// Add metaboxes to the 'Product' CPT
$meta_boxes[] = array(
'id' => 'bhww_woo_tabs_metabox',
'title' => 'Additional Product Information - <strong>Optional</strong>',
'pages' => array( 'product' ), // Which post type to associate with?
'context' => 'normal',
'priority' => 'default',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Ingredients', 'cmb' ),
'desc' => __( 'Anything you enter here will be displayed on the Ingredients tab.', 'cmb' ),
'id' => $prefix . 'ingredients_wysiwyg',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
),
array(
'name' => __( 'Benefits', 'cmb' ),
'desc' => __( 'Anything you enter here will be displayed on the Benefits tab.', 'cmb' ),
'id' => $prefix . 'benefits_wysiwyg',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
),
),
);
return $meta_boxes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment