向/从data-product_variations
产品单页中的属性表单。在使用WooCommerce时,我正在与产品库图像和产品变体进行一些交互。
基本上,我需要能够在woocommerce_variation_has_changed
事件
我能够在连接到的同时传递并获取数据属性single_product_large_thumbnail_size
和woocommerce_single_product_image_thumbnail_html
.
我有not 能够在woocommerce_variation_has_changed
事件我所理解的(?)那是woocommerce_variation_has_changed
触发器从data-product_variations
对象插入与产品变体相关的图像标记。
综上所述,如何将数据属性添加到data-product_variations
对象在woocommerce_variation_has_changed
事件
这是对象在data-product_variations
看起来像。基本上我需要通过data-attr
当woocommerce_variation_has_changed
踢进来。
data-product_variations="[{
"variation_id": 373,
"variation_is_visible": true,
"variation_is_active": true,
"is_purchasable": true,
"display_price": 100,
"display_regular_price": 100,
"attributes": {
"attribute_pa_chain-length": "80cm"
},
"image_src": "",
"image_link": "",
"image_title": "",
"image_alt": "",
"image_caption": "",
"image_srcset": "",
"image_sizes": "",
"price_html": "<span class=\\"price\\"><span class=\\"woocommerce-Price-amount amount\\"><span class=\\"woocommerce-Price-currencySymbol\\">£<\\/span>100.00<\\/span><\\/span>",
"availability_html": "",
"sku": "",
"weight": " kg",
"dimensions": "",
"min_qty": 1,
"max_qty": null,
"backorders_allowed": false,
"is_in_stock": true,
"is_downloadable": false,
"is_virtual": false,
"is_sold_individually": "no",
"variation_description": ""
}]"
SO网友:Michael Aro
jQuery(document).on(\'found_variation.wc-variation-form\', \'form.variations_form\', function(event, variation_data) {
//this is called when a valid productis found
});
jQuery(document).on(\'change.wc-variation-form\', \'form.variations_form\', function(event) {
//this function is called when the user clicks or changes the dropdown
});
您正在寻找的PHP函数是
apply_filters(
\'woocommerce_available_variation\',
array(
\'attributes\' => $variation->get_variation_attributes(),
\'availability_html\' => wc_get_stock_html( $variation ),
\'backorders_allowed\' => $variation->backorders_allowed(),
\'dimensions\' => $variation->get_dimensions( false ),
\'dimensions_html\' => wc_format_dimensions( $variation->get_dimensions( false ) ),
\'display_price\' => wc_get_price_to_display( $variation ),
\'display_regular_price\' => wc_get_price_to_display( $variation, array( \'price\' => $variation->get_regular_price() ) ),
\'image\' => wc_get_product_attachment_props( $variation->get_image_id() ),
\'image_id\' => $variation->get_image_id(),
\'is_downloadable\' => $variation->is_downloadable(),
\'is_in_stock\' => $variation->is_in_stock(),
\'is_purchasable\' => $variation->is_purchasable(),
\'is_sold_individually\' => $variation->is_sold_individually() ? \'yes\' : \'no\',
\'is_virtual\' => $variation->is_virtual(),
\'max_qty\' => 0 < $variation->get_max_purchase_quantity() ? $variation->get_max_purchase_quantity() : \'\',
\'min_qty\' => $variation->get_min_purchase_quantity(),
\'price_html\' => $show_variation_price ? \'<span class="price">\' . $variation->get_price_html() . \'</span>\' : \'\',
\'sku\' => $variation->get_sku(),
\'variation_description\' => wc_format_content( $variation->get_description() ),
\'variation_id\' => $variation->get_id(),
\'variation_is_active\' => $variation->variation_is_active(),
\'variation_is_visible\' => $variation->variation_is_visible(),
\'weight\' => $variation->get_weight(),
\'weight_html\' => wc_format_weight( $variation->get_weight() ),
),
$this,
$variation
);
这是在这里找到的
https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-product-variable.php#L325WC_Product_Variable -> get_available_variation( $variation )