Code Duplication    Length = 7-10 lines in 5 locations

includes/class-wc-shortcodes.php 1 location

@@ 839-848 (lines=10) @@
836
	 * @access private
837
	 */
838
	private static function _maybe_add_category_args( $args, $category, $operator ) {
839
		if ( ! empty( $category ) ) {
840
			$args['tax_query'] = array(
841
				array(
842
					'taxonomy' => 'product_cat',
843
					'terms'    => array_map( 'sanitize_title', explode( ',', $category ) ),
844
					'field'    => 'slug',
845
					'operator' => $operator
846
				)
847
			);
848
		}
849
850
		return $args;
851
	}

includes/cli/class-wc-cli-product.php 1 location

@@ 690-699 (lines=10) @@
687
			'meta_query'     => array(),
688
		);
689
690
		if ( ! empty( $args['type'] ) ) {
691
			$types                   = explode( ',', $args['type'] );
692
			$query_args['tax_query'] = array(
693
				array(
694
					'taxonomy' => 'product_type',
695
					'field'    => 'slug',
696
					'terms'    => $types,
697
				),
698
			);
699
		}
700
701
		// Filter products by category
702
		if ( ! empty( $args['category'] ) ) {

includes/api/class-wc-rest-products-controller.php 1 location

@@ 160-168 (lines=9) @@
157
		}
158
159
		// Filter product type by slug.
160
		if ( ! empty( $request['type'] ) ) {
161
			$terms = explode( ',', $request['type'] );
162
163
			$tax_query[] = array(
164
				'taxonomy' => 'product_type',
165
				'field'    => 'slug',
166
				'terms'    => $terms,
167
			);
168
		}
169
170
		// Filter by attribute and term.
171
		if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) {

includes/class-wc-query.php 2 locations

@@ 661-667 (lines=7) @@
658
			);
659
		}
660
661
		if ( ! empty( $args['product_cat'] ) ) {
662
			$tax_query[ 'product_cat' ] = array(
663
				'taxonomy' => 'product_cat',
664
				'terms'    => array( $args['product_cat'] ),
665
				'field'    => 'slug',
666
			);
667
		}
668
669
		if ( ! empty( $args['product_tag'] ) ) {
670
			$tax_query[ 'product_tag' ] = array(
@@ 669-675 (lines=7) @@
666
			);
667
		}
668
669
		if ( ! empty( $args['product_tag'] ) ) {
670
			$tax_query[ 'product_tag' ] = array(
671
				'taxonomy' => 'product_tag',
672
				'terms'    => array( $args['product_tag'] ),
673
				'field'    => 'slug',
674
			);
675
		}
676
677
		return $tax_query;
678
	}