WooCommerce中存在一个显示错误,即在任何;“产品数据”;设置选项卡。试试看:
// Display a custom field in product admin pages
add_action( \'woocommerce_product_options_general_product_data\', \'add_product_custom_wysiwyg_field\' );
function add_product_custom_wysiwyg_field() {
global $product_object;
echo \'<div class="product_custom_field">
<p>\' . __( "Mer information" ) . \'</p>
<div style="padding:9px;">\';
$content = $product_object->get_meta( $meta_key );
wp_editor( $content, \'_technical_specs\', [\'textarea_rows\' => 6] );
echo \'</div></div>\';
}
您将得到类似的结果(它会产生一些JS错误):
The best way is to add a custom metabox 相反,就像产品简短描述一样:
因此,您重新访问的代码将改为:
// Add custom Meta box to admin products pages
add_action( \'add_meta_boxes\', \'create_product_technical_specs_meta_box\' );
function create_product_technical_specs_meta_box() {
add_meta_box(
\'custom_product_meta_box\',
__( \'Technical specs\', \'cmb\' ),
\'add_custom_content_meta_box\',
\'product\',
\'normal\',
\'default\'
);
}
// Custom metabox content in admin product pages
function add_custom_content_meta_box( $post ){
$product = wc_get_product($post->ID);
$content = $product->get_meta( \'_technical_specs\' );
echo \'<div class="product_technical_specs">\';
wp_editor( $content, \'_technical_specs\', [\'textarea_rows\' => 10]);
echo \'</div>\';
}
// Save WYSIWYG field value from product admin pages
add_action( \'woocommerce_admin_process_product_object\', \'save_product_custom_wysiwyg_field\', 10, 1 );
function save_product_custom_wysiwyg_field( $product ) {
if ( isset( $_POST[\'_technical_specs\'] ) )
$product->update_meta_data( \'_technical_specs\', wp_kses_post( $_POST[\'_technical_specs\'] ) );
}
// Add "technical specs" product tab
add_filter( \'woocommerce_product_tabs\', \'add_technical_specs_product_tab\', 10, 1 );
function add_technical_specs_product_tab( $tabs ) {
$tabs[\'test_tab\'] = array(
\'title\' => __( \'Mer information\', \'woocommerce\' ),
\'priority\' => 50,
\'callback\' => \'display_technical_specs_product_tab_content\'
);
return $tabs;
}
// Display "technical specs" content tab
function display_technical_specs_product_tab_content() {
global $product;
echo \'<div class="wrapper-technical_specs">\' . $product->get_meta( \'_technical_specs\' ) . \'</div>\';
}
代码进入功能。活动子主题(或主题)的php文件或任何插件文件。