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

查看:160
本文介绍了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?

aprec任何帮助!

aprec any help!

推荐答案

万一有人偶然发现了这个问题未来:
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_variation_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天全站免登陆