WooCommerce:变化变化后触发事件 [英] WooCommerce: trigger event after change of variation

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

问题描述

我们使用 Woocommerce 来销售彩盒.大多数情况下选择了可变产品选项.

We use Woocommerce to sell colorboxes. Mostly the variable-product option is chosen.

我们添加了一个带有调色板的模式对话框,客户可以从中选择颜色.这是 woocommerce 常见下拉菜单的旁边.

We added a modal dialog with a color palette, where the customer can chose a color from. This is next to the common dropdown of woocommerce.

问题是,当我将正确的 SlugValue 传递给下拉列表时(从调色板中选择它后),下拉列表中的值是正确的,但需要触发以发布价格的事件不起作用.

Problem is, when I pass the right SlugValue to the dropdown (after it gets chosen from palette) then the value in the dropdown is correct, but the event that need to be fired to publish the price doens't works.

我已经尝试触发下拉菜单的 onchange 事件,但没有任何反应.

I already tried to fire the onchange event of the dropdown, but nothing happend.

谁能告诉我,需要触发哪个事件,以及如何触发?

Can anybody tell me, which event needs to be triggered, and how?

预知任何帮助!

推荐答案

以防将来有人偶然发现:WooCommerce 在整个 add-to-cart-variation.js 中提供触发器,允许您挂钩网站的更改事件.您可以在该文件中找到所有可用的文件,但在这种情况下可能最有帮助的文件可以这样使用

In case anyone stumbles across this in the future: WooCommerce provides triggers throughout the add-to-cart-variation.js which allows you to hook into change events for the website. You can find all of them available in that file, but one which will likely help most in this case can be used as such

$( ".variations_form" ).on( "woocommerce_variation_select_change", function () {
    // Fires whenever variation selects are changed
} );

$( ".single_variation_wrap" ).on( "show_variation", function ( event, variation ) {
    // Fired when the user selects all the required dropdowns / attributes
    // and a final variation is selected / shown
} );

您想要挂钩的触发器是 .on() 中的第一个参数.以下是一些帮助您入门的内容:

Where the trigger you want to hook into is the first argument inside .on(). Here's a few below to get you started:

woocommerce_varization_select_change 在选择改变时触发.

show_variation 在找到变体时被触发,并且实际上会将找到的变体对象传递给您,因此您可以直接访问价格,而无需手动过滤选择.

show_variation is fired when it finds a variation, and will actually pass you the variation object that is found so you can get direct access to the price without having to filter through the selects manually.

您可以筛选并找到其余的 此处.

You can sift through and find the rest here.

这篇关于WooCommerce:变化变化后触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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