Skip to content

Instantly share code, notes, and snippets.

@netwizards
Created February 16, 2024 18:50
Show Gist options
  • Select an option

  • Save netwizards/9014cb9383885f4ff30bb17294bc1f78 to your computer and use it in GitHub Desktop.

Select an option

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
// 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