【发布时间】:2017-07-22 16:05:03
【问题描述】:
我目前已将元数据添加到产品变体 woocommerce_product_after_variable_attributes 和 woocommerce_save_product_variation Guide here。
function custom_woocommerce_product_after_variable_attributes($loop, $variation_data, $variation)
{
woocommerce_wp_select([
'id' => 'field_1['.absint($variation->ID).']',
'label' => 'Field 1 ',
'value' => get_post_meta(absint($variation->ID), 'field_1', true),
'options' => [
'1' => '1',
'2' => '2',
'3' => '3',
],
]);
}
add_action('woocommerce_product_after_variable_attributes', 'custom_woocommerce_product_after_variable_attributes', 10, 3);
function custom_woocommerce_save_product_variation($post_id)
{
$field1 = $_POST['field_1'][$post_id];
if (! empty($field1)) {
update_post_meta(absint($post_id), 'field_1', esc_html($field1));
}
}
add_action('woocommerce_save_product_variation', 'custom_woocommerce_save_product_variation', 10, 2);
然后在 js 中挂钩到 single_variation_wrap 当变体发生变化时。这在 3.0.5 中运行良好,但自从在 js 中更新到 3.1.1 后,我不再获取自定义 meta_data 的变化。
$('.single_variation_wrap').on('show_variation', function(event, variation) {
console.log(variation.meta_data);
});
meta_data 信息已不存在。
有人解决这个问题吗?任何帮助将不胜感激。
【问题讨论】:
-
感谢@LoicTheAztec,我已经用相关信息更新了我的问题。
标签: wordpress woocommerce variations