/*
Theme Name:           Flatsome
Theme URI:            http://flatsome.uxthemes.com
Author:               UX-Themes
Author URI:           https://uxthemes.com
Description:          Multi-Purpose Responsive WooCommerce Theme
Version:              3.20.9
Requires at least:    6.4
Requires PHP:         7.4
WC requires at least: 8.3
Text Domain:          flatsome
License:              https://themeforest.net/licenses
License URI:          https://themeforest.net/licenses
*/


/***************
All custom CSS should be added to Flatsome > Advanced > Custom CSS,
or in the style.css of a Child Theme.
***************/


// ===== AST Lightweight SEO Layer =====
add_filter('document_title_parts', function ($parts) {
    if (is_singular('product')) {
        $t = get_post_meta(get_the_ID(), '_seo_title', true);
        if ($t) $parts['title'] = $t;
    }
    return $parts;
});
add_action('wp_head', function () {
    if (!is_singular('product')) return;
    $id = get_the_ID();
    $t = get_post_meta($id, '_seo_title', true);
    $d = get_post_meta($id, '_seo_desc', true);
    if ($t) echo '<meta property="og:title" content="' . esc_attr($t) . '">' . "\n";
    if ($d) {
        echo '<meta name="description" content="' . esc_attr($d) . '">' . "\n";
        echo '<meta property="og:description" content="' . esc_attr($d) . '">' . "\n";
    }
}, 1);
add_filter('wp_get_attachment_image_attributes', function ($attr) {
    if (empty($attr['alt']) && is_product()) {
        $attr['alt'] = get_the_title();
    }
    return $attr;
});
// ===== END AST SEO =====
