Code Duplication    Length = 21-24 lines in 2 locations

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

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