Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/261: Prevent "Sync with Square" from unchecking in Firefox #266

Draft
wants to merge 10 commits into
base: trunk
Choose a base branch
from
22 changes: 13 additions & 9 deletions src/js/admin/wc-square-admin-products.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ jQuery( document ).ready( ( $ ) => {
}
};

const productType = $( '#product-type' ).val();
toggleSyncProductMeta( productType );

// fire once on page load
handleAttributes( syncCheckboxID );

Expand Down Expand Up @@ -569,13 +572,10 @@ jQuery( document ).ready( ( $ ) => {
// initial page load handling.
} ).trigger( 'change' );

// trigger an update if the product type changes.
$( '#product-type' ).on( 'change', ( e ) => {
if ( 'complete' === document.readyState ) {
triggerUpdate();
}
$( '#product-type' ).on( 'change', function( e ) {
toggleSyncProductMeta( $( e.target ).val() );
} ).trigger( 'change' );
triggerUpdate();
} );

// Sync stock from the Square.
$('#woocommerce-product-data').on(
Expand All @@ -601,7 +601,7 @@ jQuery( document ).ready( ( $ ) => {
}
);

$( '#product-type, #_square_gift_card' ).on( 'change', function() {
function handleGiftCard() {
const productType = $( '#product-type' ).val();
const squareGiftCardCheckbox = $( '#_square_gift_card' );
const isGiftCard = squareGiftCardCheckbox.prop( 'checked' );
Expand Down Expand Up @@ -640,7 +640,11 @@ jQuery( document ).ready( ( $ ) => {
$( 'label[for="_downloadable"]' ).hide();
}
}
} ).trigger( 'change' );
}

handleGiftCard();

$( '#product-type, #_square_gift_card' ).on( 'change', handleGiftCard );

// Sync stock from the Square.
$('#woocommerce-product-data').on(
Expand Down Expand Up @@ -677,7 +681,7 @@ jQuery( document ).ready( ( $ ) => {
} );

/**
* Hides unnecessary meta fields when Variatble product is set as Gift Card.
* Hides unnecessary meta fields when Variable product is set as Gift Card.
* @returns void
*/
function observeVariations() {
Expand Down
Loading