Merge pull request #19044 from woocommerce/fix/19030

Make terms logic match for breadcrumb and widget
This commit is contained in:
Claudio Sanches 2018-02-20 13:18:11 -03:00 committed by GitHub
commit 99a72a6929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -144,7 +144,13 @@ class WC_Breadcrumb {
if ( 'product' === get_post_type( $post ) ) {
$this->prepend_shop_page();
if ( $terms = wc_get_product_terms( $post->ID, 'product_cat', array( 'orderby' => 'parent', 'order' => 'DESC' ) ) ) {
$terms = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_breadcrumb_product_terms_args', array(
'orderby' => 'parent',
'order' => 'DESC',
) ) );
if ( $terms ) {
$main_term = apply_filters( 'woocommerce_breadcrumb_main_term', $terms[0], $terms );
$this->term_ancestors( $main_term->term_id, 'product_cat' );
$this->add_crumb( $main_term->name, get_term_link( $main_term ) );

View File

@ -136,13 +136,15 @@ class WC_Widget_Product_Categories extends WC_Widget {
$this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
} elseif ( is_singular( 'product' ) ) {
$product_category = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_product_categories_widget_product_terms_args', array(
$terms = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_product_categories_widget_product_terms_args', array(
'orderby' => 'parent',
'order' => 'DESC',
) ) );
if ( ! empty( $product_category ) ) {
$this->current_cat = end( $product_category );
$this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
if ( $terms ) {
$main_term = apply_filters( 'woocommerce_product_categories_widget_main_term', $terms[0], $terms );
$this->current_cat = $main_term;
$this->cat_ancestors = get_ancestors( $main_term->term_id, 'product_cat' );
}
}