如何从WooCommerce禁用smoothState.js添加到购物车按钮和登录/注册链接



我刚刚在我目前工作的WooCommerce商店上实现了smoothState.js。现场演示可以通过以下链接找到:http://demos.oosh.co/bt

我现在只有两个问题:

  1. 当您单击"添加到购物车"按钮时,默认的WooCommerce AJAX调用似乎受到了干扰,就好像页面通过smoothState.js操作一样。我想知道如何在"添加到购物车"按钮上停用smoothState.js。

  2. 例如,当您单击登出并注销时,尝试重新登录或注册只会运行smoothState.js,不会将这些其他链接重定向到相应的操作。因此,在这些登录和注册链接上,我也想禁用smoothState.js.

是否有人能更胜任这项工作?

顺便说一句,这是我用来调用smoothState.js的代码https://webdesign.tutsplus.com/tutorials/how-to-integrate-smoothstatejs-into-a-wordpress-theme--cms-26610

// Using smoothstate-js to Ajax-load pages
(function($) {
function addBlacklistClass() {
$('a').each( function() {
if (this.href.indexOf('/wp-admin/') !== -1 ||
this.href.indexOf('/wp-login.php') !== -1) {
$(this).addClass('wp-link');
}
});
}
$(function() {
addBlacklistClass();
var settings = {
anchors: 'a',
blacklist: '.wp-link',
onStart: {
duration: 320,
render: function ($container) {
$container.addClass('slide-out');
}
},
onAfter: function($container) {
addBlacklistClass();
var $hash = $(window.location.hash);
if ($hash.length !== 0) {
var offsetTop = $hash.offset().top;
$('body, html').animate({
scrollTop: (offsetTop - 60),
}, {
duration: 320
} );
}
$container.removeClass('slide-out');
}
};
$('#app').smoothState(settings);
});
})(jQuery); // End smoothstate-js

非常感谢你的帮助。

我在黑名单函数中添加了几行代码,这似乎解决了问题。不过,我会继续调查,以确保一切正常。现在,除了你想改进我的代码,我想我很好。

(function($) {
function addBlacklistClass() {
$('a').each( function() {
if (this.href.indexOf('/wp-admin/') !== -1 ||
this.href.indexOf('/wp-login.php') !== -1 ||
this.href.indexOf('/?add-to-cart') !== -1 ||
this.href.indexOf('?remove_item') !== -1) {
$(this).addClass('no-smoothState');
}
});
$('input[type="submit"]').each(function() {
$(this).addClass('no-smoothState');
});
}
$(function() {
addBlacklistClass();
var settings = {
anchors: 'a',
forms: 'input',
blacklist: '.no-smoothState',
onStart: {
duration: 320,
render: function ($container) {
$container.addClass('slide-out');
}
},
onAfter: function($container) {
addBlacklistClass();
var $hash = $(window.location.hash);
if ($hash.length !== 0) {
var offsetTop = $hash.offset().top;
$('body, html').animate({
scrollTop: (offsetTop - 60),
}, {
duration: 320
} );
}
$container.removeClass('slide-out');
}
};
$('#app').smoothState(settings);
});
})(jQuery);

最新更新