【问题标题】:update checkout after adding product添加产品后更新结帐
【发布时间】:2021-12-29 18:38:33
【问题描述】:

我正在尝试做类似的事情:Woocommerce update checkout ajax!我正在为我的客户构建一个多步骤表单,客户使用 ajax 在购物车中添加产品。将产品添加到购物车时,我需要更新结帐。我尝试做一个 onclick 功能,所以当用户在购物车中添加产品时,结帐步骤更新而不刷新页面:

jQuery('#test').on('click',function(){
    $( document.body ).trigger( 'update_checkout' );
})

但它不起作用,我觉得我缺少一些明显的东西....有什么提示吗? :)

【问题讨论】:

    标签: wordpress woocommerce plugins


    【解决方案1】:

    你的代码是正确的,你必须用 jQuery 替换 $

     //Paste this code in theme footer.php file and check it on checkout page
    <?php if (is_checkout()) { ?>
      <button id="test">Click here to update checkout</button>
      <script type="text/javascript">
        jQuery(document).ready(function(){
          jQuery('#test').on('click',function(){ alert("pp");
            jQuery( document.body ).trigger( 'update_checkout' );
          });
        });
      </script>
    <?php } ?>
    

    代码已经过测试,一切正常。

    【讨论】:

    • 感谢我设法用 ajax 更新结帐,但现在我有另一个问题啊哈......它显示了结帐,但它不会加载必要的条带脚本来显示卡字段......
    • 好的我有一个解决方案检查下一篇文章 jQuery( document ).on( 'updated_checkout', function() { //在这里写代码来触发事件 console.log(''); }) ;
    【解决方案2】:

    结帐更新后触发此事件

    jQuery( document ).on( 'updated_checkout', function() { 
    
        //Write code here to fire event 
        console.log('run');
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 2012-12-05
      • 2019-04-03
      • 1970-01-01
      • 2021-12-25
      • 2021-06-28
      相关资源
      最近更新 更多