Last active
June 12, 2019 15:50
-
-
Save cubehrends/b1b9246bdc3a471785c0b1c7c33326b0 to your computer and use it in GitHub Desktop.
Adding Brand Archive Link to Single Product Summary in WooCommerce
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_action( 'woocommerce_single_product_summary', 'add_brand_to_single_product_summary', 6 ); | |
function add_brand_to_single_product_summary() { | |
global $post; | |
if ( ! $post_id && ! $post ) | |
return; | |
if ( ! $post_id ) | |
$post_id = $post->ID; | |
$brands = wp_get_post_terms( $post_id, 'product_brand', array( "fields" => "ids" ) ); | |
$output = null; | |
if ( count( $brands ) > 0 ) { | |
ob_start(); | |
foreach( $brands as $brand ) { | |
$term = get_term_by( 'id', $brand, 'product_brand' ); | |
echo '<p class="produkt-brand"><a href="' . get_term_link( $term, 'product_brand' ) . '">' . $term->name . '</a></p>'; | |
} | |
$output = ob_get_clean(); | |
} | |
echo $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment