简体   繁体   English

WooCommerce:停止滚动到结帐页面上的错误消息

[英]WooCommerce: Stop scrolling to error message on checkout page

Usually WooCommerce scrolls to .form.checkout if there is an error on the checkout form.如果结帐表单上有错误,WooCommerce 通常会滚动到.form.checkout I want this to stop because it somehow interferes with ScrollMagic.js.我希望它停止,因为它以某种方式干扰了 ScrollMagic.js。

If I don't enqueue ScrollMagic.js everything is working fine, but with ScrollMagic.js enabled the page just jumps a bit to the top.如果我不排队 ScrollMagic.js 一切正常,但启用 ScrollMagic.js 页面只是跳到顶部。

I tried to use $(document.body).on('checkout_error', function () { $( 'html, body' ).stop(); } but it doesn't work.我尝试使用$(document.body).on('checkout_error', function () { $( 'html, body' ).stop(); }但它不起作用。

If I use如果我使用

$(document.body).on('checkout_error', function () {
    // There was a validation error
    console.log('checkout_error triggered');
});

There are no log messages in the console.控制台中没有日志消息。 Why isn't there anything happening?为什么什么都没有发生? How can I stop the WooCommerce animation?如何停止 WooCommerce 动画?

According to this article you could try this?根据这篇文章你可以试试这个吗?

jQuery( document ).ajaxComplete( function() {
    if ( jQuery( 'body' ).hasClass( 'woocommerce-checkout' ) || jQuery( 'body' ).hasClass( 'woocommerce-cart' ) ) {
        jQuery( 'html, body' ).stop();
    }
} );

Now my console logs are appearing.现在我的控制台日志出现了。 I didn't change anything at all, but jQuery('html, body').stop();我根本没有改变任何东西,但是jQuery('html, body').stop(); doesn't trigger.不会触发。

But by using GSAP ScrollToPlugin I can now scroll to the ul.woocommerce-error using但是通过使用 GSAP ScrollToPlugin 我现在可以滚动到ul.woocommerce-error使用

$(document.body).on('checkout_error', function () {
  TweenLite.to(window, 1, {scrollTo:"ul.woocommerce-error"});
  console.log('checkout_error triggered');
});

as described here: https://greensock.com/ScrollToPlugin .如此处所述: https : //greensock.com/ScrollToPlugin

I know it's really old topic but I found much easier solution.我知道这是一个非常古老的话题,但我找到了更简单的解决方案。 Just edit 3 notice templates (error.php, notice.php, success.php) and remove role="alert" and that's it.只需编辑 3 个通知模板(error.php、notice.php、success.php)并删除 role="alert" 就可以了。 The scroll funciton won't find element to scroll to.滚动功能找不到要滚动到的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM