Code Duplication    Length = 22-27 lines in 2 locations

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

@@ 79-100 (lines=22) @@
76
	/**
77
	 * On a product page, add a click event listener to "Add to Cart" button click
78
	 */
79
	public function add_to_cart() {
80
81
		if ( ! is_single() ) {
82
			return;
83
		}
84
85
		$blogid = Jetpack::get_option( 'id' );
86
		global $product;
87
88
		wc_enqueue_js(
89
			"jQuery( '" . esc_js( '.single_add_to_cart_button' ) . "' ).click( function() {
90
				_wca.push( {
91
					'_en': 'woocommerceanalytics_add_to_cart',
92
					'blog_id': " . esc_js( $blogid ) . ",
93
					'pi': '" . esc_js( $product->get_id() ) . "',
94
					'pn' : '" . esc_js( $product->get_title() ) . "',
95
					'pq': jQuery( 'input.qty' ).val() ? jQuery( 'input.qty' ).val() : '1',
96
					'ui': '" . esc_js( $this->get_user_id() ) . "',
97
				} );
98
			} );"
99
		);
100
	}
101
102
	/**
103
	 * On product lists or other non-product pages, add an event listener to "Add to Cart" button click
@@ 105-131 (lines=27) @@
102
	/**
103
	 * On product lists or other non-product pages, add an event listener to "Add to Cart" button click
104
	 */
105
	public function loop_add_to_cart() {
106
		$blogid   = Jetpack::get_option( 'id' );
107
		$selector = '.add_to_cart_button:not(.product_type_variable, .product_type_grouped)';
108
109
		wc_enqueue_js(
110
			"jQuery( '" . esc_js( $selector ) . "' ).click( function() {
111
				var productID = jQuery( this ).data( 'product_id' );
112
				var productDetails = {
113
					'id': productID,
114
					'quantity': jQuery( this ).data( 'quantity' ),
115
				};
116
				_wca.push( {
117
					'_en': 'woocommerceanalytics_product_view',
118
					'blog_id': '" . esc_js( $blogid ) . "',
119
					'pi': productDetails.id,
120
					'ui': '" . esc_js( $this->get_user_id() ) . "',
121
				} );
122
				_wca.push( {
123
					'_en': 'woocommerceanalytics_add_to_cart',
124
					'blog_id': " . esc_js( $blogid ) . ",
125
					'pi': productDetails.id,
126
					'pq': productDetails.quantity,
127
					'ui': '" . esc_js( $this->get_user_id() ) . "',
128
				} );
129
			} );"
130
		);
131
	}
132
133
	/**
134
	 * On the cart page, add an event listener for removal of product click