Created
November 25, 2015 03:53
-
-
Save MilanSavaliya/356a1625fbc680ce7d3b to your computer and use it in GitHub Desktop.
Append custom taxonomy to the product description with Marketpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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