Created
December 4, 2013 19:01
-
-
Save tjtate/7793415 to your computer and use it in GitHub Desktop.
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
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