Code Duplication    Length = 7-8 lines in 2 locations

includes/wc-product-functions.php 1 location

@@ 241-247 (lines=7) @@
238
		$category_object = apply_filters( 'wc_product_post_type_link_product_cat', $terms[0], $terms, $post );
239
		$product_cat     = $category_object->slug;
240
241
		if ( $category_object->parent ) {
242
			$ancestors = get_ancestors( $category_object->term_id, 'product_cat' );
243
			foreach ( $ancestors as $ancestor ) {
244
				$ancestor_object = get_term( $ancestor, 'product_cat' );
245
				$product_cat     = $ancestor_object->slug . '/' . $product_cat;
246
			}
247
		}
248
	} else {
249
		// If no terms are assigned to this post, use a string instead (can't leave the placeholder there).
250
		$product_cat = _x( 'uncategorized', 'slug', 'woocommerce' );

includes/class-wc-ajax.php 1 location

@@ 1522-1529 (lines=8) @@
1519
			foreach ( $terms as $term ) {
1520
				$term->formatted_name = '';
1521
1522
				if ( $term->parent ) {
1523
					$ancestors = array_reverse( get_ancestors( $term->term_id, 'product_cat' ) );
1524
					foreach ( $ancestors as $ancestor ) {
1525
						if ( $ancestor_term = get_term( $ancestor, 'product_cat' ) ) {
1526
							$term->formatted_name .= $ancestor_term->name . ' > ';
1527
						}
1528
					}
1529
				}
1530
1531
				$term->formatted_name              .= $term->name . ' (' . $term->count . ')';
1532
				$found_categories[ $term->term_id ] = $term;