Skip to content

Instantly share code, notes, and snippets.

@cubehrends
Last active June 12, 2019 15:50
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 cubehrends/b1b9246bdc3a471785c0b1c7c33326b0 to your computer and use it in GitHub Desktop.
Save cubehrends/b1b9246bdc3a471785c0b1c7c33326b0 to your computer and use it in GitHub Desktop.
Adding Brand Archive Link to Single Product Summary in WooCommerce
<?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