Home New Guten Forums WoodMart support forum How to change “add to cart” in archive to product page link?

How to change “add to cart” in archive to product page link?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #510000

    smadarev
    Participant

    Hi,
    I want to change the archive default “add to cart” to be “view the product” – on click open product page.
    How can I do that?

    #510148

    Hello,

    Add the below code to the functions.php file into the Child theme

    // Replace add to cart button by a linked button to the product in Shop and archives pages
    add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
    function replace_loop_add_to_cart_button( $button, $product  ) {
        // Not needed for variable products
        if( $product->is_type( 'variable' ) ) return $button;
    
        // Button text here
        $button_text = __( "View product", "woocommerce" );
    
        return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
    }

    Best Regards.

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)