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