Yucaree
Yucaree

Reputation: 13

Replace WooCommerce product short description by selected variation description

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?

Upvotes: 0

Views: 2517

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253784

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.

Upvotes: 2

Related Questions