Note : has auto click feature, meaning the add to cart button
will automatically be clicked when the page is loaded. if
there is more than one atcb on the page then the setting
is ignored. the setting will always work on the product
detail page but will target only the first atcb
By : Thomas Creedon < http://www.tomsWeb.consulting/ >
*/
/*
the url can be any valid url. It can be a full (external to your site) one
like 'http://www.tomsWeb.consulting/' or a partial (internal to your site)
one like '/cart'
*/
const url = '/cart';
const autoClick = false;
// do not change anything below, there be the borg here
// bail if no mutation observer available
if ( ! ( 'MutationObserver' in window ) ) return;
const observer = new MutationObserver ( function ( mutations ) {
$.each ( mutations, function ( ) {
if ( this.attributeName != 'class' ) return;
const $element = $( this.target );
if ( ! $element.hasClass ( 'cart-added' ) ) return;
location.href = url;
} );
} );
// start listening for changes in specified elements
const $addToCartButtons = $( '.sqs-add-to-cart-button-wrapper' );
if ( ! $addToCartButtons.length ) return; // bail if no buttons
$addToCartButtons.each ( function ( ) {
const element = $( '.sqs-add-to-cart-button', this )
.get ( 0 );
observer.observe ( element, {
attributes : true
} );
} );
// begin auto click add to cart button
if ( ! autoClick ) return; // bail if not auto click
const b = twcsl.page.store.detail.is && $addToCartButtons.length > 1;
if ( ! b ) return;
$( '.sqs-add-to-cart-button-inner', $addToCartButtons.first ( ) )
.click ( );
// end auto click add to cart button
} );