Search code examples
wordpresswoocommerceproducthook-woocommerce

WooCommerce add Read more button for Product list


I use WooCommerce and in my product lists, the user will link to the product page after they click a picture or title.

I want to add ” read more ” button right after my short description in the product list, something like read more button for blogs

I found what page I must add PHP code, I also add this code to my functions.php

function read_more() {
    global $product;
    if ($product){
        $url = esc_url($product->get_permalink() );
        echo '<a rel="nofollow" href="' .$url .'" class="read_more">read_more</a>';
    }
}

then I add this code to my product list template :

add_action('woocommerce_after_shop_loop_item_title','read_more');

but nothing adds.


Solution

  • Add this code in your active theme functions.php file

    add_action( 'woocommerce_after_shop_loop_item_title', 'read_more' );
    
    function read_more() {
        global $product;
        if ( $product ) {
            $url = esc_url( $product->get_permalink() );
            echo '<a rel="nofollow" href="' . $url . '" class="read_more">read_more</a>';
        }
    }