0

I would like to have a short description in the widget Featured Products or before the list Related Products.

How can I do that?

1 Answer 1

0

Featured Products is a widget. Inserting content here is tricky, because there is no real hook. But what the widget does is a simple call to WP_Query, and here we can use the action loop_start. We just have to make sure to find the correct loop_start, because there are probably many more on each page.

So first create a function for the description:

function print_woo_featured_products_desc()
{
    remove_action( current_filter(), __FUNCTION__ );

    echo 'This is my description.';
}

This function removes itself from the current filter (loop_start) and prints your description. Now we have to activate it somewhere:

add_action( 'woocommerce_loaded', function() {

    add_filter( 'dynamic_sidebar_params', function( $params )
    {
        if ( $params[0]['widget_name'] === __( 'WooCommerce Featured Products', 'woocommerce' ) )
            add_action( 'loop_start', 'print_woo_featured_products_desc' );

        return $params;
    });
});

Explaining what happens would take too much time. And I did that already:

The related products are a template. Just copy woocommerce/templates/single-product/related.php to your theme into /themename/woocommerce/single-product/related.php, and add your description after

<h2><?php _e( 'Related Products', 'woocommerce' ); ?></h2>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.