questions

How to auto copy title into description field for all WooCommerce variation products?

Rate this post

I have lots of variable products and the description field is left blank by default, but I have other plugins which are set to display the Variation Description field on the front end. How can I get my site to copy the variation name (Pink Set No Box, Pink Set With Box, Green Set No Box etc.) into the corresponding variation description field?

As well as doing it for all existing products, it would need to do it for all new products being added as well.

So how can I copy automatically for product variations, the title into description field in WooCommerce?

 

✔️Solution:

Instead of copying the variation product name in the variation description, you can assign it to the description dynamically using this very simple hooked function:

add_filter( 'woocommerce_product_variation_get_description', 'wc_product_variation_get_description_filter', 10, 2 );
function wc_product_variation_get_description_filter( $description, $product ){
    return $product->get_name();
}

Or you can also append it to the description using:

add_filter( 'woocommerce_product_variation_get_description', 'wc_product_variation_get_description_filter', 10, 2 );
function wc_product_variation_get_description_filter( $description, $product ){
    return $description . $product->get_name();
}

Or prepend it with:

add_filter( 'woocommerce_product_variation_get_description', 'wc_product_variation_get_description_filter', 10, 2 );
function wc_product_variation_get_description_filter( $description, $product ){
    return $product->get_name() . $description;
}

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


On some cases when products have been created since a long time, the attributes are not displayed in the product variation name… You will need to add the following line:

add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_true' );

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

Leave a Reply

Your email address will not be published.

Back to top button