/*
Theme Name:           Flatsome
Theme URI:            http://flatsome.uxthemes.com/
Author:               UX-Themes
Author URI:           http://www.uxthemes.com/
Description:          Multi-Purpose Responsive WooCommerce Theme
Version:              3.15.6
Requires at least:    5.0.0
Requires PHP:         5.6.20
WC requires at least: 4.4.0
Text Domain:          flatsome
License:              http://themeforest.net/licenses
License URI:          http://themeforest.net/licenses
*/


/***************
All custom CSS should be added to Flatsome > Advanced > Custom CSS,
or in the style.css of a Child Theme.
***************/
add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2);

function change_attachement_image_attributes( $attr, $attachment ){
    // Get post parent
    $parent = get_post_field( 'post_parent', $attachment);

    // Get post type to check if it's product
    $type = get_post_field( 'post_type', $parent);
    if( $type != 'product' ){
        return $attr;
    }

    /// Get title
    $title = get_post_field( 'post_title', $parent);

    $attr['alt'] = $title;
    $attr['title'] = $title;

    return $attr;
}