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?
Thanks for your feedback!

Leave a Reply
You must be logged in to post a comment.