ebkod ebkod - 2 months ago 11
PHP Question

Add text in this PHP code?

function woocommerce_template_product_description() {
wc_get_template( 'single-product/tabs/description.php' );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_product_description', 20 );

This code prints a product description, but I'd like to add the text "Description:" before the description itself without having it on a separate line. How do I go about that? I am a total beginner when it comes to coding. Thanks!


In WordPress/WooCommerce Product are nothing but a Post. So the the product description is treated as the_content of a post.

If you just want to add custom text/content before the Product Description then just use the_content filter.

Here is the code.

function theme_slug_filter_the_content($content)
    //Only for single product page.
    if (is_product())
        $prepend = 'Description';
        $content = $prepend . $content;
    return $content;

add_filter('the_content', 'theme_slug_filter_the_content', 9); // <-- Choose some priority < 

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and fully functional.