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