Remove link from the image on product single page on WooCommerce


Working on a different WooCommerce site got me to do a lot of customisation. I recently need it a way to remove the link from main image or a product from the single product page.

This can be done by changing some code on WooCommerce templates but i wanted to do it another way. Here is the solution i found. Put the following code into the functions.php file for your theme:

function dex_remove_product_image_link( $html, $post_id ) {
    return preg_replace( "!<(a|/a).*?>!", '', $html );
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'dex_remove_product_image_link', 10, 2 );


Please enter your comment!
Please enter your name here