Replace add to cart button with a read more linked to product page on shop pages in WooCommerce 3

前端 未结 4 1483
逝去的感伤
逝去的感伤 2020-12-06 03:37

I am using woocommerce and I have the following issue:

  • The products are displayed in the homepage with their price and add to cart button.
  • Add to ca
4条回答
  •  情深已故
    2020-12-06 04:19

    Replacing the button add to cart by a link to the product in Shop and archives pages for woocommerce 3+:

    add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
    function replacing_add_to_cart_button( $button, $product  ) {
        $button_text = __("View product", "woocommerce");
        $button = '' . $button_text . '';
    
        return $button;
    }
    

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

    This code is tested on WooCommerce 3+ and works. You can customize the text of button and you will get something like:

提交回复
热议问题