Skip to content

Instantly share code, notes, and snippets.

@felipe-pita
Created May 27, 2019 13:14
Show Gist options
  • Save felipe-pita/603ffe5e5b4b8d31e0ebffea3ffaa60c to your computer and use it in GitHub Desktop.
Save felipe-pita/603ffe5e5b4b8d31e0ebffea3ffaa60c to your computer and use it in GitHub Desktop.
/**
* Breadcrumb na single de produto
*/
add_action( 'woocommerce_single_product_summary', 'single_product_breadcrumb', 0 );
function single_product_breadcrumb() {
global $post;
$out = '<div class="breadcrumbs">';
$out .= '<div class="breadcrumbs__container container">';
$out .= '<a href="' . get_site_url() . '">Home</a> » ';
$term_list = wp_get_post_terms($post->ID, 'product_cat', ['fields' => 'all', 'parent' => 0]);
$primary_term = $term_list[0];
if (isset($primary_term)) {
$out .= '<a href="' . get_term_link($primary_term, 'product_cat') . '">' . $primary_term->name . '</a>';
}
$out .= '</div>';
$out .= '</div>';
echo $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment