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

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