I'd like to be able to add a subtitle to my products in Woocommerce only on the shop page. I have it set up as a catalog right now, since I'm not actively selling my products yet, so I have disabled the add to cart button and the prices. I would like to be able to say how many colors the product comes in as a subtitle. I have read up on adding meta boxes with Woocommerce, and found this solution and added it to my functions.php, but it doesn't appear to be working on my site (I can't find where to enter the information for the product!)
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' => __( 'Colors', 'cmb' ),
'desc' => __( 'Anything you enter here will be displayed on the Colors tab.', 'cmb' ),
'id' => $prefix . 'ingredients_wysiwyg',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
),
),
);
return $meta_boxes;
}
Related
I'm using Metabox Plugin in WP and generate a field using MB online generator.
add_filter( 'rwmb_meta_boxes', 'bq_homemeta_register_meta_boxes' );
function bq_homemeta_register_meta_boxes( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => esc_html__( 'Homepage Meta', 'bequik' ),
'id' => 'home_meta',
'context' => 'normal',
'pages' => 'page',
'fields' => [
[
'type' => 'image_advanced',
'name' => esc_html__( 'Hero Image', 'bequik' ),
'id' => $prefix . 'hero_image',
'max_file_uploads' => 1,
],
],
];
return $meta_boxes;
}
I wanted the metabox field to display only in home page in the WP admin editor.
I tried the include/exclude extension but failed to work.
Thank you!
I would like to use an Array returned by a Woocommerce filter as a value in a Redux Framework field. I do understand the filter returns after the Woocommerce plugin has loaded. I've tried to move the Redux::setSection method inside the filter function but it appears the section method is not called in that case. Any suggestions?
$statuses;
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
$statuses = $order_statuses;
return $order_statuses;
}
/*Need to pass $statuses to the Redux::setSection*/
Redux::setSection( $opt_name, array(
'title' => __( 'Text Options', 'redux-framework-demo' ),
'desc' => __( 'For full documentation on this field, visit: ', 'redux-framework-demo' ) . 'http://docs.reduxframework.com/core/fields/text/',
'id' => 'opt-text-subsection',
'icon' => 'el el-home',
'subsection' => false,
'fields' => array(
array(
'id'=>'multi-text',
'type' => 'multi_text',
'title' => __('Multi Text Option - Color Validated', 'redux-framework-demo'),
'validate' => 'color',
'subtitle' => __('If you enter an invalid color it will be removed. Try using the text "blue" as a color. ;)', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo')
),
array(
'id' => 'opt-select',
'type' => 'select',
'title' => __('Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
// Must provide key => value pairs for select options
'options' => $statuses,
'default' => '2',
)
)
) );
Use the Redux data field. You can make a custom callback, and the data will always be up to date.
https://docs.redux.io/configuration/argument-data.html#using-a-custom-callback
Also if you need to update the option from outside of Redux (say on WooCommerce update of that value) you can set it this way:
https://docs.redux.io/guides/advanced-updating-an-option-manually.html
I am using penny auction wordpress theme, as i am new to wordpress. My question is to add more fields in side meta-box by using child theme, So for this I have successfully created and activated child theme, but I am stuck here to how can I add more text fields in meta box by using child theme functions file?
The easiest way to do that is to install the Meta Box plugin (https://wordpress.org/plugins/meta-box/), then add this to your child theme's functions.php file:
function yourprefix_register_meta_boxes( $meta_boxes ) {
$prefix = 'metaboxprefix_';
$meta_boxes[] = array(
'id' => 'samplefield',
'title' => __( 'Your Meta Box Title', 'yourtextdomain' ),
'post_types' => 'post',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => __( 'Your Text Field', 'yourtextdomain' ),
'id' => $prefix . 'yourfieldid',
'type' => 'text',
),
)
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'yourprefix_register_meta_boxes' );
For future reference: http://metabox.io/
I am trying to add an excerpt option to my category page, to display instead of my description.
So basically, I need a box on this screen which will be able to be used as preview text.
The code used to create this taxonomy is:
add_action( 'init', 'create_product_cat_external' );
function create_product_cat_external() {
register_taxonomy(
'ExternalProducts',
'products',
array(
'label' => __( 'External Products' ),
'rewrite' => array( 'slug' => 'externalproducts' ),
'hierarchical' => true,
)
);
}
and the box needs to be here:
You can use CMB2 plugin and put this in your functions.php for example:
add_action( 'cmb2_admin_init', 'yourprefix_register_taxonomy_metabox' );
function yourprefix_register_taxonomy_metabox() {
$prefix = 'yourprefix_term_';
$cmb_term = new_cmb2_box( array(
'id' => $prefix . 'edit',
'object_types' => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => array( 'products'), // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
) );
$cmb_term->add_field( array(
'name' => __('Excerpt', 'default'),
'id' => $prefix . 'excerpt',
'type' => 'wysiwyg',
'on_front' => false,
) );
}
I'm a newbie Wordpress developer & I can't figure out how to get the options chosen in my Custom Meta Boxes to populate on my posts. For example, this is how my admin panel looks when creating new posts:
http://i.stack.imgur.com/9RGz8.jpg
To give you an example of my code for this section that is in my meta.php file... It's:
//POST META BOXES
'post'=> array(
array(
'name' => 'Home Type',
'id' => PEXETO_META_PREFIX.'text',
'type' => 'select',
'options' => array( array( 'name'=>'1', 'id'=>'1' ),
array( 'name'=>'2', 'id'=>'2' ),
array( 'name'=>'3', 'id'=>'3' ),
array( 'name'=>'4', 'id'=>'4' ),
array( 'name'=>'5', 'id'=>'5' ) ),
'desc' => '...'
),
array(
'name' => 'Listing Status',
'id' => PEXETO_META_PREFIX.'text',
'type' => 'select',
'options' => array( array( 'name'=>'1', 'id'=>'1' ),
array( 'name'=>'2', 'id'=>'2' ),
array( 'name'=>'3', 'id'=>'3' ) ),
'desc' => '...'
),
array(
'name' => 'Lot Size',
'id' => PEXETO_META_PREFIX.'text',
'type' => 'text',
'desc' => '...'
),
What I'm trying to do is set it up so that each meta box will generate a two column row in my actual post. The left side would show the title of the box, and the right side would show the answer given by the user. An example of this is below:
http://i.stack.imgur.com/suJTq.jpg
Any help with this one would be greatly appreciated as I'm stuck...
Thanks.
You should look into get_post_meta()
Then something like this to echo those metas out in a table:
$metas = get_post_meta( get_the_ID() );
echo '<table>';
foreach( $metas as $key => $meta ) {
printf('<tr><th>%s</th><td>%s</td></tr>',
$key, $meta[0] );
}
echo '</table>';