Code Duplication    Length = 21-24 lines in 2 locations

modules/woocommerce-analytics/classes/wp-woocommerce-analytics-universal.php 2 locations

@@ 292-312 (lines=21) @@
289
	 * Listen for clicks on the "Update Cart" button to know if an item has been removed by
290
	 * updating its quantity to zero
291
	 */
292
	public function remove_from_cart_via_quantity() {
293
		$blogid = Jetpack::get_option( 'id' );
294
295
		wc_enqueue_js( "
296
			jQuery( 'button[name=update_cart]' ).on( 'click', function() {
297
				var cartItems = jQuery( '.cart_item' );
298
				cartItems.each( function( item ) {
299
					var qty = jQuery( this ).find( 'input.qty' );
300
					if ( qty && qty.val() === '0' ) {
301
						var productID = jQuery( this ).find( '.product-remove a' ).data( 'product_id' );
302
						_wca.push( {
303
							'_en': 'woocommerceanalytics_remove_from_cart',
304
							'blog_id': '" . esc_js( $blogid ) . "',
305
							'pi': productID,
306
							'ui': '" . esc_js( $this->get_user_id() ) . "',
307
						} );
308
					}
309
				} );
310
			} );
311
		" );
312
	}
313
314
	/**
315
	 * Get the current user id
@@ 136-159 (lines=24) @@
133
	/**
134
	 * On the cart page, add an event listener for removal of product click
135
	 */
136
	public function remove_from_cart() {
137
138
		// We listen at div.woocommerce because the cart 'form' contents get forcibly
139
		// updated and subsequent removals from cart would then not have this click
140
		// handler attached.
141
		$blogid = Jetpack::get_option( 'id' );
142
		wc_enqueue_js(
143
			"jQuery( 'div.woocommerce' ).on( 'click', 'a.remove', function() {
144
				var productID = jQuery( this ).data( 'product_id' );
145
				var quantity = jQuery( this ).parent().parent().find( '.qty' ).val()
146
				var productDetails = {
147
					'id': productID,
148
					'quantity': quantity ? quantity : '1',
149
				};
150
				_wca.push( {
151
					'_en': 'woocommerceanalytics_remove_from_cart',
152
					'blog_id': '" . esc_js( $blogid ) . "',
153
					'pi': productDetails.id,
154
					'pq': productDetails.quantity,
155
					'ui': '" . esc_js( $this->get_user_id() ) . "',
156
				} );
157
			} );"
158
		);
159
	}
160
161
	/**
162
	 * Adds the product ID to the remove product link (for use by remove_from_cart above) if not present