Last active
May 8, 2023 10:50
-
-
Save bhwebworks/df6b827586addede3403 to your computer and use it in GitHub Desktop.
Add custom metaboxes to WooCommerce products
This file contains hidden or 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
/** | |
* 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