Merge pull request #25760 from helgatheviking/issues/25759-conditionally-disable-ajax-add-to-cart
Conditionally disable ajax add to cart
This commit is contained in:
commit
7206365250
|
@ -17,6 +17,7 @@ jQuery( function( $ ) {
|
|||
.on( 'click', '.add_to_cart_button', { addToCartHandler: this }, this.onAddToCart )
|
||||
.on( 'click', '.remove_from_cart_button', { addToCartHandler: this }, this.onRemoveFromCart )
|
||||
.on( 'added_to_cart', this.updateButton )
|
||||
.on( 'ajax_request_not_sent.adding_to_cart', this.updateButton )
|
||||
.on( 'added_to_cart removed_from_cart', { addToCartHandler: this }, this.updateFragments );
|
||||
};
|
||||
|
||||
|
@ -69,6 +70,12 @@ jQuery( function( $ ) {
|
|||
$thisbutton.removeClass( 'added' );
|
||||
$thisbutton.addClass( 'loading' );
|
||||
|
||||
// Allow 3rd parties to validate and quit early.
|
||||
if ( false === $( document.body ).triggerHandler( 'should_send_ajax_request.adding_to_cart', [ $thisbutton ] ) ) {
|
||||
$( document.body ).trigger( 'ajax_request_not_sent.adding_to_cart', [ false, false, $thisbutton ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
var data = {};
|
||||
|
||||
// Fetch changes that are directly added by calling $thisbutton.data( key, value )
|
||||
|
@ -159,10 +166,13 @@ jQuery( function( $ ) {
|
|||
|
||||
if ( $button ) {
|
||||
$button.removeClass( 'loading' );
|
||||
$button.addClass( 'added' );
|
||||
|
||||
if ( fragments ) {
|
||||
$button.addClass( 'added' );
|
||||
}
|
||||
|
||||
// View cart text.
|
||||
if ( ! wc_add_to_cart_params.is_cart && $button.parent().find( '.added_to_cart' ).length === 0 ) {
|
||||
if ( fragments && ! wc_add_to_cart_params.is_cart && $button.parent().find( '.added_to_cart' ).length === 0 ) {
|
||||
$button.after( ' <a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' +
|
||||
wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>' );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue