Code Duplication    Length = 21-24 lines in 2 locations

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

@@ 114-137 (lines=24) @@
111
	/**
112
	 * On the cart page, add an event listener for removal of product click
113
	 */
114
	public function remove_from_cart() {
115
116
		// We listen at div.woocommerce because the cart 'form' contents get forcibly
117
		// updated and subsequent removals from cart would then not have this click
118
		// handler attached.
119
		$blogid = Jetpack::get_option( 'id' );
120
		wc_enqueue_js(
121
			"jQuery( 'div.woocommerce' ).on( 'click', 'a.remove', function() {
122
				var productID = jQuery( this ).data( 'product_id' );
123
				var quantity = jQuery( this ).parent().parent().find( '.qty' ).val()
124
				var productDetails = {
125
					'id': productID,
126
					'quantity': quantity ? quantity : '1',
127
				};
128
				_wca.push( {
129
					'_en': 'woocommerceanalytics_remove_from_cart',
130
					'blog_id': '" . esc_js( $blogid ) . "',
131
					'pi': productDetails.id,
132
					'pq': productDetails.quantity,
133
					'ui': '" . esc_js( $this->get_user_id() ) . "',
134
				} );
135
			} );"
136
		);
137
	}
138
139
	/**
140
	 * Adds the product ID to the remove product link (for use by remove_from_cart above) if not present
@@ 277-297 (lines=21) @@
274
	 * Listen for clicks on the "Update Cart" button to know if an item has been removed by
275
	 * updating its quantity to zero
276
	 */
277
	public function remove_from_cart_via_quantity() {
278
		$blogid = Jetpack::get_option( 'id' );
279
280
		wc_enqueue_js(
281
			"
282
			jQuery( 'button[name=update_cart]' ).on( 'click', function() {
283
				var cartItems = jQuery( '.cart_item' );
284
				cartItems.each( function( item ) {
285
					var qty = jQuery( this ).find( 'input.qty' );
286
					if ( qty && qty.val() === '0' ) {
287
						var productID = jQuery( this ).find( '.product-remove a' ).data( 'product_id' );
288
						_wca.push( {
289
							'_en': 'woocommerceanalytics_remove_from_cart',
290
							'blog_id': '" . esc_js( $blogid ) . "',
291
							'pi': productID,
292
							'ui': '" . esc_js( $this->get_user_id() ) . "',
293
						} );
294
					}
295
				} );
296
			} );
297
		"
298
		);
299
	}
300