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