Woocommerce-add_to_cart触发器 [英] Woocommerce - added_to_cart trigger

查看:99
本文介绍了Woocommerce-add_to_cart触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将特定产品添加到购物车时,我试图使用WooCommerce的add_to_cart触发器来触发弹出窗口.到目前为止,我已经成功完成了以下任务:

I am trying to use the WooCommerce added_to_cart trigger to trigger a popup when adding specific products to cart. So far, I have succeeded with the following:

jQuery('body').on('added_to_cart',function() {
        alert("testing!");
    });

将任何产品添加到购物车时,这将显示一个警告框.但是,我希望仅针对特定类别显示警报.但是,如何检查添加到购物车中的产品属于哪个类别?

This shows an alert box when any product is added to cart. However, i would like the alert to only show up for specific categories. But how can I check which category the product added to cart belongs to?

添加到购物车的来源在这里: https://github.com/woothemes /woocommerce/blob/master/assets/js/frontend/add-to-cart.js

The source for adding to cart is here: https://github.com/woothemes/woocommerce/blob/master/assets/js/frontend/add-to-cart.js

与此相关的触发器:

$( document.body ).trigger( 'added_to_cart', [ fragments, cart_hash, $thisbutton ] );

推荐答案

所以我也遇到了这个确切的问题,而且修复非常简单.

So I ran into this exact issue as well, and the fix is quite simple.

您的函数实际上是正确的,只需要将其包装在.ready()函数中即可.

Your function is actually correct, it just needs to be wrapped in a .ready() function.

您的代码如下:

jQuery(document).ready(function($){
    $('body').on( 'added_to_cart', function(){
        alert("testing!");
    });
});

这篇关于Woocommerce-add_to_cart触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆