Skip to content

Instantly share code, notes, and snippets.

@tjtate
Created December 4, 2013 19:01
Show Gist options
  • Save tjtate/7793415 to your computer and use it in GitHub Desktop.
Save tjtate/7793415 to your computer and use it in GitHub Desktop.
function lfbwc_get_author_links($post_id) {
if (!class_exists('WC_Product')) {
return array();
}
$product = get_product($post_id);
$attrs = $product->get_attributes();
$values = array();
if (!empty($attrs['pa_product-author'])) {
$author_terms = $attrs['pa_product-author'];
$author_terms = wp_get_post_terms($product->id, $author_terms['name']);
if (is_wp_error($author_terms)) {
return $values;
}
foreach ($author_terms as $author_term) {
$link = get_term_link((int) $author_term->term_id, 'pa_product-author');
if (is_wp_error($link)) {
continue;
}
$values[] = sprintf('<a href="%s">%s</a>', esc_url($link), esc_html($author_term->name));
}
}
return $values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment