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

@@ 151-159 (lines=9) @@
148
		}
149
150
		// Filter product type by slug.
151
		if ( ! empty( $request['type'] ) ) {
152
			$terms = explode( ',', $request['type'] );
153
154
			$tax_query[] = array(
155
				'taxonomy' => 'product_type',
156
				'field'    => 'slug',
157
				'terms'    => $terms,
158
			);
159
		}
160
161
		// Filter by attribute and term.
162
		if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) {

includes/class-wc-query.php 2 locations

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