
Aggiungere campi custom ad una categoria WooCommerce
function nuovocampo_in_categoria(){ ?>
<div class="form-field">
<label for="nuovocampo"><?php _e('Descrizione in basso', 'it'); ?></label>
<textarea name="nuovocampo" id="nuovocampo"></textarea>
</div>
<?php
}
function ctg_modifica_nuovocampo($term){
$term_id = $term->term_id;
$nuovocampo = get_term_meta($term_id, 'nuovocampo', true);
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="nuovocampo"><?php _e('Descrizione in basso', 'it'); ?></label></th>
<td>
<?php
wp_editor($nuovocampo ? $nuovocampo : '', 'nuovocampo');
</td>
</tr>
<?php
}
add_action('product_cat_add_form_fields', 'nuovocampo_in_categoria', 10, 1);
add_action('product_cat_edit_form_fields', 'ctg_modifica_nuovocampo', 10, 1);
function salva_nuovocampo($term_id) {
if(isset($_POST['nuovocampo']) && $_POST['nuovocampo'] != ''){
$nuovocampo = $_POST['nuovocampo'];
update_term_meta($term_id, 'nuovocampo', $nuovocampo);
}
}
add_action('edited_product_cat', 'salva_nuovocampo', 10, 1);
add_action('create_product_cat', 'salva_nuovocampo', 10, 1);
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content';
return $tabs;
}
function woo_custom_description_tab_content() {
global $post;
echo $post->post_excerpt;
}