Merge pull request #15956 from woocommerce/add-cart-readdition-notice
Use ajax when restoring an item in the cart
This commit is contained in:
commit
ee87024d82
File diff suppressed because one or more lines are too long
|
@ -266,6 +266,7 @@ jQuery( function( $ ) {
|
||||||
this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this );
|
this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this );
|
||||||
this.quantity_update = this.quantity_update.bind( this );
|
this.quantity_update = this.quantity_update.bind( this );
|
||||||
this.item_remove_clicked = this.item_remove_clicked.bind( this );
|
this.item_remove_clicked = this.item_remove_clicked.bind( this );
|
||||||
|
this.item_restore_clicked = this.item_restore_clicked.bind( this );
|
||||||
this.update_cart = this.update_cart.bind( this );
|
this.update_cart = this.update_cart.bind( this );
|
||||||
|
|
||||||
$( document ).on(
|
$( document ).on(
|
||||||
|
@ -291,6 +292,10 @@ jQuery( function( $ ) {
|
||||||
'click',
|
'click',
|
||||||
'.woocommerce-cart-form .product-remove > a',
|
'.woocommerce-cart-form .product-remove > a',
|
||||||
this.item_remove_clicked );
|
this.item_remove_clicked );
|
||||||
|
$( document ).on(
|
||||||
|
'click',
|
||||||
|
'.woocommerce-cart .restore-item',
|
||||||
|
this.item_restore_clicked );
|
||||||
$( document ).on(
|
$( document ).on(
|
||||||
'change input',
|
'change input',
|
||||||
'.woocommerce-cart-form .cart_item :input',
|
'.woocommerce-cart-form .cart_item :input',
|
||||||
|
@ -528,6 +533,34 @@ jQuery( function( $ ) {
|
||||||
block( $form );
|
block( $form );
|
||||||
block( $( 'div.cart_totals' ) );
|
block( $( 'div.cart_totals' ) );
|
||||||
|
|
||||||
|
$.ajax( {
|
||||||
|
type: 'GET',
|
||||||
|
url: $a.attr( 'href' ),
|
||||||
|
dataType: 'html',
|
||||||
|
success: function( response ) {
|
||||||
|
update_wc_div( response );
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
unblock( $form );
|
||||||
|
unblock( $( 'div.cart_totals' ) );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle when a restore item link is clicked.
|
||||||
|
*
|
||||||
|
* @param {Object} evt The JQuery event
|
||||||
|
*/
|
||||||
|
item_restore_clicked: function( evt ) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
var $a = $( evt.currentTarget );
|
||||||
|
var $form = $( 'form.woocommerce-cart-form' );
|
||||||
|
|
||||||
|
block( $form );
|
||||||
|
block( $( 'div.cart_totals' ) );
|
||||||
|
|
||||||
$.ajax( {
|
$.ajax( {
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: $a.attr( 'href' ),
|
url: $a.attr( 'href' ),
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -462,7 +462,7 @@ class WC_Form_Handler {
|
||||||
// Don't show undo link if removed item is out of stock.
|
// Don't show undo link if removed item is out of stock.
|
||||||
if ( $product->is_in_stock() && $product->has_enough_stock( $cart_item['quantity'] ) ) {
|
if ( $product->is_in_stock() && $product->has_enough_stock( $cart_item['quantity'] ) ) {
|
||||||
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
|
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
|
||||||
$removed_notice .= ' <a href="' . esc_url( WC()->cart->get_undo_url( $cart_item_key ) ) . '">' . __( 'Undo?', 'woocommerce' ) . '</a>';
|
$removed_notice .= ' <a href="' . esc_url( WC()->cart->get_undo_url( $cart_item_key ) ) . '" class="restore-item">' . __( 'Undo?', 'woocommerce' ) . '</a>';
|
||||||
} else {
|
} else {
|
||||||
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
|
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue