It sort-of worked. The enclosing a tag has a title attribute as well. That’s being removed but leaving the second title attribute in the img tag. So we need to remove two title attributes:
add_filter ('woocommerce_single_product_image_html', 'my_function');
function my_function($html) {
$start = stripos($html, 'alt="');
if ($start) {
$end = stripos($html, '"', $start + 5);
$html = substr($html, 0, $start - 1).substr($html, $end + 1);
}
$start = stripos($html, 'title="'); // attribute in a tag
if ($start) {
$end = stripos($html, '"', $start + 7);
$html = substr($html, 0, $start - 1).substr($html, $end + 1);
}
$start = stripos($html, 'title="'); // attribute in img tag
if ($start) {
$end = stripos($html, '"', $start + 7);
$html = substr($html, 0, $start - 1).substr($html, $end + 1);
}
return $html;
}