在 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/