Skip to content

Instantly share code, notes, and snippets.

@MilanSavaliya
Created November 25, 2015 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MilanSavaliya/356a1625fbc680ce7d3b to your computer and use it in GitHub Desktop.
Save MilanSavaliya/356a1625fbc680ce7d3b to your computer and use it in GitHub Desktop.
Append custom taxonomy to the product description with Marketpress
<?php
add_filter( 'the_content', 'append_custom_taxonomy_to_product_content', '', 1);
function append_custom_taxonomy_to_product_content( $content ){
if( get_post_type() == 'product' ){
$taxonomySlug = 'brands';
$terms = get_the_terms( get_the_id(), $taxonomySlug );
// var_dump( $terms );
if( !empty( $terms ) ){
$termNames = '';
for( $i = 0; $i < count( $terms ) ; $i++ ){
$currentProcessingTerm = $terms[$i];
$termName = ucfirst( $currentProcessingTerm->name );
// var_dump( $currentProcessingTerm );
$termLink = get_term_link( $currentProcessingTerm->term_id, $taxonomySlug );
if( is_wp_error( $termLink ) ){
$termLink = '#';
}
$termNames .= '<a href="' . esc_url( $termLink ) . '">' . $termName . '</a>' . ( ( ( $i + 1 ) != count( $terms ) ) ? ', ' : '' );
}
$html ='';
$html .= '
<div class="custom-taxonomy '. $taxonomySlug .'">
'. $termNames .'
</div>
';
//apend generated html block for brands to title
return $content . $html;
}
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment