Home › Forums › Basel support forum › Change default values in "Product Setting (custom metabox from theme)"
Change default values in "Product Setting (custom metabox from theme)"
- This topic has 5 replies, 2 voices, and was last updated 6 years, 3 months ago by Artem Temos.
-
AuthorPosts
-
February 5, 2018 at 1:29 pm #37527
heartitParticipantHi guys,
Absolutely love your theme, bought it 3 times so far and will continue to do so.
We would like to change the default values of the custom metabox found when editing a product. I have attached an image of the default values when you create a new product, and the values we would like to be default when a new product is created.
This would then allow a shop manager to create new products without having to change these values every time they add a new product.
Hope this makes sense! Thank you in advance for any help.
Cheers,
Joe.
Attachments:
You must be logged in to view attached files.February 5, 2018 at 2:18 pm #37548
Artem TemosKeymasterHello,
Thank you so much for contacting our support center.
Unfortunately, there is no easy way to do this in our theme and you will need to perform additional code customization to achieve this.
1. In the file
basel/inc/classes/Metaboxes.php
you need to replace method calledproduct_metaboxes()
with the following onepublic function product_metaboxes() { global $basel_prefix, $basel_transfer_options; // Start with an underscore to hide fields from custom fields list $basel_prefix = '_basel_'; $taxonomies_list = array( '' => 'Select' ); $taxonomies = get_taxonomies(); foreach ( $taxonomies as $taxonomy ) { $taxonomies_list[$taxonomy] = $taxonomy; } $basel_metaboxes = new_cmb2_box( array( // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // true to keep the metabox closed by default 'id' => 'product_metabox', 'title' => esc_html__( 'Product Setting (custom metabox from theme)', 'basel' ), 'object_types' => array('product'), // post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Add "New" label', 'basel' ), 'desc' => esc_html__( 'You can add "New" label to this product', 'basel' ), 'id' => $basel_prefix . 'new_label', 'type' => 'checkbox', ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Hide related products', 'basel' ), 'desc' => esc_html__( 'You can hide related products on this page', 'basel' ), 'id' => $basel_prefix . 'related_off', 'type' => 'checkbox', 'default' => true, ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Hide tabs headings', 'basel' ), 'desc' => esc_html__( 'Description and Additional information', 'basel' ), 'id' => $basel_prefix . 'hide_tabs_titles', 'type' => 'checkbox', 'default' => true, ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Grid swatch attribute to display', 'basel' ), 'desc' => esc_html__( 'Choose attribute that will be shown on products grid for this particular product', 'basel' ), 'id' => $basel_prefix . 'swatches_attribute', 'type' => 'select', 'options' => $taxonomies_list ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Product video URL', 'basel' ), 'desc' => esc_html__( 'Vimeo or YouTube video url. For example: https://www.youtube.com/watch?v=1zPYW6Ipgok', 'basel' ), 'id' => $basel_prefix . 'product_video', 'type' => 'text', ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Instagram product hashtag', 'basel' ), 'desc' => esc_html__( 'Insert tag that will be used to display images from instagram from your customers. For example: <strong>#nike_rush_run</strong>', 'basel' ), 'id' => $basel_prefix . 'product_hashtag', 'type' => 'text', ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Product background', 'basel' ), 'id' => $basel_prefix . 'product-background', 'type' => 'colorpicker', ) ); $basel_local_transfer_options = array( 'single_product_style', 'product_design', 'main_layout', 'sidebar_width', ); foreach ($basel_local_transfer_options as $field) { $cmb_field = $this->redux2cmb_field( $field ); $basel_metaboxes->add_field( $cmb_field ); } $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Custom sidebar for this product', 'basel' ), 'id' => $basel_prefix . 'custom_sidebar', 'type' => 'select', 'options' => basel_get_sidebars_array(), 'default' => 'sidebar-1', ) ); $blocks = array_flip(basel_get_static_blocks_array()); $blocks = (array)'None' + $blocks; $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Extra content block', 'basel' ), 'desc' => esc_html__( 'You can create some extra content with WPBakery Page Builder (in Admin panel / HTML Blocks / Add new) and add it to this product', 'basel' ), 'id' => $basel_prefix . 'extra_content', 'type' => 'select', 'options' => $blocks, 'default' => '261', ) ); $basel_metaboxes->add_field( array( 'name' => esc_html__( 'Extra content position', 'basel' ), 'id' => $basel_prefix . 'extra_position', 'type' => 'radio_inline', 'options' => array( 'after' => esc_html__( 'After content', 'basel' ), 'before' => esc_html__( 'Before content', 'basel' ), 'prefooter' => esc_html__( 'Prefooter', 'basel' ), ), 'default' => 'prefooter' ) ); $basel_transfer_options = array_merge( $basel_transfer_options, $basel_local_transfer_options ); }
2. Replace this method
redux2cmb_field()
with this codepublic function redux2cmb_field( $field ) { if( ! class_exists('Redux') ) return array( 'id' => '', 'type' => '', 'name' => '', 'options' => '', 'default' => 'default', ); $prefix = '_basel_'; $field = Redux::getField($this->opt_name, $field); $options = array(); switch ($field['type']) { case 'image_select': $type = 'select'; $options = ( ! empty( $field['options'] ) ) ? array_merge( array('default' => array('title' => 'Inherit') ), $field['options'] ) : array(); foreach ($options as $key => $option) { $options[$key] = ( isset( $options[$key]['alt'] ) ) ? $options[$key]['alt'] : $options[$key]['title']; } break; case 'button_set': $type = 'radio_inline'; $options['default'] = 'Inherit'; foreach ($field['options'] as $key => $value) { $options[$key] = $value; } break; case 'select': $type = 'select'; $options['inherit'] = 'Inherit'; foreach ($field['options'] as $key => $value) { $options[$key] = $value; } break; case 'switch': $type = 'checkbox'; break; default: $type = $field['type']; break; } $cmb_field = array( 'id' => $prefix . $field['id'], 'type' => $type, 'name' => $field['title'], 'options' => $options, 'default' => '', ); if ( $field['id'] == 'sidebar_width' ) { $cmb_field['default'] = 3; } if ( $field['id'] == 'product_design' ) { $cmb_field['default'] = 'default'; } if ( $field['id'] == 'main_layout' ) { $cmb_field['default'] = 'sidebar-left'; } return $cmb_field; }
Kind Regards
XTemos StudioFebruary 5, 2018 at 5:09 pm #37606
heartitParticipantHi guys,
It worked for everything EXCEPT the ‘Product Background’ field and the ‘Extra Content Block’ field.
The ‘Product Background’ field should automatically be #f9f9f9 when adding a new product.
The ‘Extra Content Block’ field should automatically be the HTML block we created (Special Offers). I’m not sure what info you’d need to set it as default, but its shortcode is [html_block id="3151"].Thanks!
February 5, 2018 at 8:13 pm #37666
Artem TemosKeymasterUnfortunately, we are not able to change this for the background color option. As for the extra content block, you need to specify your ID on this line
'default' => '261',
February 5, 2018 at 8:56 pm #37677
heartitParticipantThank you Artem, much appreciated!
February 6, 2018 at 7:40 am #37735
Artem TemosKeymasterYou are welcome!
-
AuthorPosts
The topic ‘Change default values in "Product Setting (custom metabox from theme)"’ is closed to new replies.
- You must be logged in to create new topics. Login / Register