'Refresh variation product description after variant changed in Woocommerce
so I've moved variation description to additional information tab in single product page, everything work like a charm, but description of each variant shows only when I click on anything at page. Of course I'd like to have it refresh instantly after variant is chosen. I've got Variation Swatches for WooCommerce plugin, which cause whole problem.
That's a piece of code I used (created by 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>
I've tried to make some script to trigger a click (as I said, when I click whatever on page, description refresh) but it doesn't work either, can anybody help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
