【问题标题】:Get Shipping Method after updated_checkout在 updated_checkout 后获取送货方式
【发布时间】:2021-12-10 16:34:28
【问题描述】:

我的目标是在没有可用的送货方式时显示弹出窗口。

我知道要使用触发器updated_checkout,但我如何从该触发器中知道,送货方式不可用?所以我可以触发显示弹出窗口。

【问题讨论】:

    标签: jquery ajax woocommerce


    【解决方案1】:

    您可以使用$( 'body' ).on( 'updated_checkout',function( data ){}); 触发update_checkout 试试下面的代码。

    function check_shipping_method_available(){
        ?>
        <script type="text/javascript">
            (function( $ ) {
                $( 'body' ).on( 'updated_checkout',function( data ){
                    if( !$('.shipping_method').length ){
                        alert('No Shipping method available');
                        // popup code
                    }
                } );
            })(jQuery);
        </script>
        <?php
    }
    add_action( 'wp_footer', 'check_shipping_method_available', 10, 1 );
    

    经过测试且有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-08
      • 2014-07-06
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 2012-08-21
      • 2019-02-20
      相关资源
      最近更新 更多