0
votes

Can I hide woocommerce short description if variable product description is visible?

Then if I reset the variation, then short description will display again and then hide the variable product description again.

Any help?

1
In practice, do you want to display either the short description of the variable product (if no option has been selected) or the short description of the chosen variation (and thus hide the short description of the variable product)? Quite right? - Vincenzo Di Gaetano

1 Answers

1
votes

To replace variable product short description by the selected variation description if it's not empty, you can use the following:

add_action( 'woocommerce_before_variations_form', 'variable_product_jquery_script' );
function variable_product_jquery_script() {
    ?>
    <style>.woocommerce-variation-description {display:none !important}</style>
    <script>
    (function($) {
        var selector  = '.woocommerce-product-details__short-description',
            form      = $('form.cart'),
            shortDesc = $(selector).html();

        form.on('show_variation', function(event, data){
            var varDesc = data.variation_description;       
            $(selector).html( varDesc ? varDesc : shortDesc );
        });

        form.on('hide_variation', function(){
            $(selector).html(shortDesc);
        });
    })(jQuery);
    </script>
    <?php
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.