Code Duplication    Length = 17-20 lines in 2 locations

modules/woocommerce-analytics/classes/wp-woocommerce-analytics-universal.php 1 location

@@ 143-159 (lines=17) @@
140
	 * @param string $key key.
141
	 * @return mixed.
142
	 */
143
	public function remove_from_cart_attributes( $url, $key ) {
144
		if ( false !== strpos( $url, 'data-product_id' ) ) {
145
			return $url;
146
		}
147
148
		$item    = WC()->cart->get_cart_item( $key );
149
		$product = $item['data'];
150
151
		$new_attributes = sprintf(
152
			'href="%s" data-product_id="%s" data-product_sku="%s"',
153
			esc_attr( $url ),
154
			esc_attr( $product->get_id() ),
155
			esc_attr( $product->get_sku() )
156
		);
157
		$url = str_replace( 'href=', $new_attributes, $url );
158
		return $url;
159
	}
160
161
	/**
162
	 * Gather relevant product information

modules/google-analytics/classes/wp-google-analytics-universal.php 1 location

@@ 273-292 (lines=20) @@
270
	/**
271
	* Adds the product ID and SKU to the remove product link (for use by remove_from_cart above) if not present
272
	*/
273
	public function remove_from_cart_attributes( $url, $key ) {
274
		if ( false !== strpos( $url, 'data-product_id' ) ) {
275
			return $url;
276
		}
277
278
		if ( ! class_exists( 'WooCommerce' ) ) {
279
			return $url;
280
		}
281
282
		$item = WC()->cart->get_cart_item( $key );
283
		$product = $item[ 'data' ];
284
285
		$new_attributes = sprintf( 'href="%s" data-product_id="%s" data-product_sku="%s"',
286
			esc_attr( $url ),
287
			esc_attr( $product->get_id() ),
288
			esc_attr( $product->get_sku() )
289
			);
290
		$url = str_replace( 'href=', $new_attributes, $url );
291
		return $url;
292
	}
293
294
	public function listing_impression() {
295
		if ( ! Jetpack_Google_Analytics_Options::enhanced_ecommerce_tracking_is_enabled() ) {