Code Duplication    Length = 16-18 lines in 2 locations

includes/admin/meta-boxes/views/html-variation-admin.php 1 location

@@ 36-53 (lines=18) @@
33
				echo '<select name="attribute_' . sanitize_title( $attribute['name'] ) . '[' . $loop . ']"><option value="">' . __( 'Any', 'woocommerce' ) . ' ' . esc_html( wc_attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
34
35
				// Get terms for attribute taxonomy or value if its a custom attribute
36
				if ( $attribute['is_taxonomy'] ) {
37
38
					$post_terms = wp_get_post_terms( $parent_data['id'], $attribute['name'] );
39
40
					foreach ( $post_terms as $term ) {
41
						echo '<option ' . selected( $variation_selected_value, $term->slug, false ) . ' value="' . esc_attr( $term->slug ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';
42
					}
43
44
				} else {
45
46
					$options = wc_get_text_attributes( $attribute['value'] );
47
48
					foreach ( $options as $option ) {
49
						$selected = sanitize_title( $variation_selected_value ) === $variation_selected_value ? selected( $variation_selected_value, sanitize_title( $option ), false ) : selected( $variation_selected_value, $option, false );
50
						echo '<option ' . $selected . ' value="' . esc_attr( $option ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
51
					}
52
53
				}
54
55
				echo '</select>';
56
			}

includes/admin/meta-boxes/class-wc-meta-box-product-data.php 1 location

@@ 649-664 (lines=16) @@
646
								echo '<select name="default_attribute_' . sanitize_title( $attribute['name'] ) . '" data-current="' . esc_attr( $variation_selected_value ) . '"><option value="">' . __( 'No default', 'woocommerce' ) . ' ' . esc_html( wc_attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
647
648
								// Get terms for attribute taxonomy or value if its a custom attribute
649
								if ( $attribute['is_taxonomy'] ) {
650
									$post_terms = wp_get_post_terms( $post->ID, $attribute['name'] );
651
652
									foreach ( $post_terms as $term ) {
653
										echo '<option ' . selected( $variation_selected_value, $term->slug, false ) . ' value="' . esc_attr( $term->slug ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';
654
									}
655
656
								} else {
657
									$options = wc_get_text_attributes( $attribute['value'] );
658
659
									foreach ( $options as $option ) {
660
										$selected = sanitize_title( $variation_selected_value ) === $variation_selected_value ? selected( $variation_selected_value, sanitize_title( $option ), false ) : selected( $variation_selected_value, $option, false );
661
										echo '<option ' . $selected . ' value="' . esc_attr( $option ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) )  . '</option>';
662
									}
663
664
								}
665
666
								echo '</select>';
667
							}