×
Black Friday Savings
00Days
:
09Hours
:
36Minutes
:
52Seconds
Use Coupon 40%OFF

Includes 1 Year Priority Support

Shop Now

WP SITES

3093 Coded Tutorials & 296 Plugins

Open External Product Link In New Tab

Copy & paste this PHP code to the end of your child themes functions file or custom code snippets plugin to make external products open in a new tab.

add_filter( 'woocommerce_loop_add_to_cart_link', 'wpsites_external_products', 10, 2 );
 
function wpsites_external_products( $link, $product ){

	if ( 'external' === $product->get_type() ) { 
  
$link = sprintf( '<a href="%s" target="_blank" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button product_type_%s">%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( $product->get_id() ),
        esc_attr( $product->get_sku() ),
        esc_attr( isset( $quantity ) ? $quantity : 1 ),
        esc_attr( $product->get_type() ),
        esc_html( $product->add_to_cart_text() )
);
	}
return $link;
}

Was this helpful?

Yes
No
Thanks for your feedback!

Leave a Reply