Adding Content To Top Of WooCommerce Product Tag Pages

Hello,

A couple weeks ago we submitted a support request to add the ability to add description content both above and below the block of product listing thumbnails on our custom 'product brand' pages. The catch was that we needed each content description to be unique for each page. In order to accomplish this, Adam Czajczyk was kind enough to provide the following code that we placed in our mu-plugin directory (see code snippet below):


<?php

// new brand description above products

function action_woocommerce_archive_description( $woocommerce_taxonomy_archive_description ) {

$q_object = get_queried_object();

if (isset($q_object->taxonomy) && $q_object->taxonomy == 'brand':wink: {

$top_description = get_term_meta( $q_object->term_id, 'top-description', true );

echo '<div class="brand-top-description">' . $top_description . '</div>';

}

};

add_action( 'woocommerce_archive_description', 'action_woocommerce_archive_description', 10 );

# extend taxonomy form

add_action( 'brand_add_form_fields', 'add_topdescription_field', 10, 2 );

function add_topdescription_field($taxonomy) {

global $feature_groups;

?><div class="form-field term-group">

<label for="top-description">Top Description</label>

<textarea id="top-description" name="top-description"></textarea>

</div><?php

}

#save additional taxonomy field

add_action( 'created_brand', 'save_topdescription_meta', 10, 2 );

function save_topdescription_meta( $term_id, $tt_id ){

if( isset( $_POST['top-description'] ) && '' !== $_POST['top-description'] ){

$group = $_POST['top-description'];

add_term_meta( $term_id, 'top-description', $group, true );

}

}

#update additional taxonomy field

add_action( 'brand_edit_form_fields', 'edit_topdescription_field', 10, 2 );

function edit_topdescription_field( $term, $taxonomy ){

// get current data

$top_description = get_term_meta( $term->term_id, 'top-description', true );

?><tr class="form-field term-group-wrap">

<th scope="row"><label for="top-description">Top Description</label></th>

<td><textarea id="top-description" name="top-description"><?php echo $top_description; ?></textarea></td>

</tr><?php

}

add_action( 'edited_brand', 'update_topdescription_meta', 10, 2 );

function update_topdescription_meta( $term_id, $tt_id ){

if( isset( $_POST['top-description'] ) && '' !== $_POST['top-description'] ){

$group = $_POST['top-description'];

update_term_meta( $term_id, 'top-description', $group );

}

}

#display top-description on brands lista

add_filter('manage_edit-brand_columns', 'add_topdescription_column' );

function add_topdescription_column( $columns ){

$columns['top_description'] = 'Top Description';

return $columns;

}

add_filter('manage_brand_custom_column', 'add_topdescription_column_content', 10, 3 );

function add_topdescription_column_content( $content, $column_name, $term_id ){

if( $column_name !== 'top_description' ){

return $content;

}

$term_id = absint( $term_id );

$top_description = get_term_meta( $term_id, 'top-description', true );

if( !empty( $top_description ) ){

$content .= esc_attr( $top_description );

}

return $content;

}


This code created a second description box on the admin back end page editor which allowed us to have unique content above and below each brand page.

We would like our 'product tag' pages to have the same functionality so we can add content above the product listing thumbnails on product tag pages as well, just like the aforementioned brand pages. Could we somehow adjust the code already provided to include the ability to add a custom description on product tag pages as well?

Please see this link for an example of one of our brand pages:

https://cncmachines.net/brand/used-haas/

I realize this request may sound rather confusing so please let me know if I can do anything to make things clearer and thank you for any help you can offer in this matter!

Take care,

Matthew