Este código es de Adding Custom Text Area to WooCommerce Product – WordPress Development Stack Exchange
Funciona hoy. No sé mañana.
Lo de siempre. Puede añadirse a un plugin, theme o… como snippet usando un plugin de snippets.
// 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>';
}
Agregar un comentario