gpt4 book ai didi

javascript - 捕获 "applied coupon"事件以触发 Woocommerce 中的 JS 函数

转载 作者:行者123 更新时间:2023-11-30 06:21:49 25 4
gpt4 key购买 nike

在 Woocommerce 中,有没有办法在像这样应用优惠券后触发 JS?

我想像这样使用它:

    $( document.body ).on( 'updated_cart_totals', function(){
//do something
});

感谢任何帮助。

最佳答案

您可以像本例中那样使用 applied_coupon 委托(delegate)事件,它会显示一个带有已应用优惠券代码的警告框(其中变量 coupon 是已应用的优惠券代码):

<script type="text/javascript">
jQuery(function($){
$( "body" ).on( 'applied_coupon', function(event, coupon){
// Example: Displaying an alert message with the applied coupon code
alert('Applied coupon code: "' + coupon + '"\n' + 'Event type: "' + event.type + '"');
});
});
</script>

经过测试并有效。

关于javascript - 捕获 "applied coupon"事件以触发 Woocommerce 中的 JS 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52688065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com