Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save hirejordansmith/5355b48d278dabfbe2aff919390b2d03 to your computer and use it in GitHub Desktop.

Select an option

Save hirejordansmith/5355b48d278dabfbe2aff919390b2d03 to your computer and use it in GitHub Desktop.
Replace WooCommerce Product Archive Add to Cart Button
<?php
// This just returns an empty value for the archive product button
add_filter( 'woocommerce_loop_add_to_cart_link', 'change_add_to_cart_loop' );
function change_add_to_cart_loop( $product ) {
global $product; // this may not be necessary as it should have pulled the object in already
return '';
}
// Then we add a new button with the same WooCommerce Markup that links directly to the product page
add_action( 'woocommerce_after_shop_loop_item', 'hjs_loop_add_to_cart', 10 );
function hjs_loop_add_to_cart() {
global $product;
echo '<form action="' . esc_url( $product->get_permalink( $product->id ) ) . '" method="get">
<button type="submit" class="single_add_to_cart_button button alt">' . __('View More', 'woocommerce') . '</button>
</form>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment