Track adding coupons to orders on edit screen.

This commit is contained in:
Jeff Stieler 2019-06-07 11:31:53 +02:00
parent 02a7654532
commit 02785bc14c
1 changed files with 32 additions and 11 deletions

View File

@ -407,9 +407,19 @@ jQuery( function ( $ ) {
},
add_coupon: function() {
window.wcTracks.recordEvent( 'order_add_coupon_click', {
order_id: woocommerce_admin_meta_boxes.post_id,
status: $( '#order_status' ).val()
} );
var value = window.prompt( woocommerce_admin_meta_boxes.i18n_apply_coupon );
if ( value != null ) {
if ( null == value ) {
window.wcTracks.recordEvent( 'order_add_coupon_cancel', {
order_id: woocommerce_admin_meta_boxes.post_id,
status: $( '#order_status' ).val()
} );
} else {
wc_meta_boxes_order_items.block();
var user_id = $( '#customer_user' ).val();
@ -425,7 +435,11 @@ jQuery( function ( $ ) {
user_email : user_email
} );
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
$.ajax( {
url: woocommerce_admin_meta_boxes.ajax_url,
data: data,
type: 'POST',
success: function( response ) {
if ( response.success ) {
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
$( '#woocommerce-order-items' ).find( '.inside' ).append( response.data.html );
@ -435,6 +449,13 @@ jQuery( function ( $ ) {
window.alert( response.data.error );
}
wc_meta_boxes_order_items.unblock();
},
complete: function() {
window.wcTracks.recordEvent( 'order_added_coupon', {
order_id: data.order_id,
status: $( '#order_status' ).val()
} );
}
} );
}
return false;