Change behavior of WooCommerce Module "Add to cart" button

Hello Builders,

I’m using WC module displaying featured products and I want to change the “add to cart” button behavior. I would like to change href of button to take the user to product page.

I’m using this code below, the href property change but the button still adding product to cart.

Please, any thoughts about what I need to do will be appreciated.

/**
	 * Alterar destino do botão principal Adicionar ao carrinho
	 *
	 * @since 1.0.0
	 */

add_filter( 'woocommerce_loop_add_to_cart_link', 'dl_alterar_destino_botao' );

	function dl_alterar_destino_botao( $product ) {
	  global $product;

	  return sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button %s product_type_%s">COMPRAR</a>',
	  esc_url( get_permalink( $product->id ) ),
	  esc_attr( $product->id ),
	  esc_attr( $product->get_sku() ),
	  esc_attr( isset( $quantity ) ? $quantity : 1 ),
	  $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
	  esc_attr( $product->product_type )
	  );
	} 

Site: http://181.224.144.163/dentalliberdade/

WP version: 4.3
WC version: 2.4.4
BB plugin version: 1.6
BB theme version: 1.3.1.2

Thanks!

I forgot to comment that in Storefront theme (WooThemes) this snippet worked perfectly, so I decided to post here on the forum.

Regards

Oo Pretty weird! After apply this filter href was pointing to the product page but when click on button was adding the product in the cart, today when I return to the problem was solved!

Hey Marlon,

Was playing around with this on my localhost when I received your latest reply. Glad it’s working fine then! Have fun with The Beaver! :slight_smile:

Ben

Thanks! Regards

I figured out what was wrong and would like to leave for the next visitors to this topic.

Actually what I was doing wrong was that the “WooCommerce enable ajax add to cart” setting was enabled. If this option is enabled even filtering the button and changing your URL will add the product to the cart.

Hey Marlon,

So cool of you to share that info! Thank you! :slight_smile:

Ben