Created
February 16, 2024 18:50
-
-
Save netwizards/9014cb9383885f4ff30bb17294bc1f78 to your computer and use it in GitHub Desktop.
Replace add to cart button by a linked button to the product in Shop and archives pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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>'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment