【发布时间】:2022-09-26 02:47:26
【问题描述】:
所以我将变体描述移动到单个产品页面的附加信息选项卡中,一切都像魅力一样工作,但每个变体的描述只有当我点击页面上的任何内容时才会显示。当然,我希望在选择变体后立即刷新。我有 WooCommerce 插件的 Variation Swatches,这会导致整个问题。
那是我使用的一段代码(由 LoicTheAztec 创建)
add_action( \'wp_footer\', \'move_variation_description\' );
function move_variation_description(){
global $product;
// Only on single product pages for variable products
if ( ! ( is_product() && $product->is_type(\'variable\') ) ) return;
// jQuery code
?>
<script type=\"text/javascript\">
jQuery(function($){
a = \'.woocommerce-variation-description\', b = a+\' p\', c = \'input.variation_id\',
d = \'#tab-additional_information\', de = $(d).html();
// On load, adding a mandatory very small delay
setTimeout(function(){
// variation ID selected by default
if( \'\' != $(c).val() && $(a).text() != \'\' )
$(d).html($(a).html());
}, 300);
// On live event (attribute select fields change)
$(\'table.variations ul li\').on( \'blur\', function(){
// variation ID is selected
if( \'\' != $(c).val() && $(a).text() != \'\' ){
$(d).html($(a).html());
}
// No variation ID selected
else {
$(d).html($(a).html()); // We set back the variable product description
}
});
});
</script>
我试图制作一些脚本来触发点击(正如我所说,当我点击页面上的任何内容时,描述刷新)但它也不起作用,有人可以帮忙吗?
标签: wordpress woocommerce