<?php
//Listar dadods do schema de produto
if (!function_exists('alt_get_schema_header')) {
    function alt_get_schema_header()
    {


        ?>

        <script type="application/ld+json" id="orgSchema">
            {
                "@context": "http://schema.org",
                "@type": "Organization",
                "url": "<?php echo get_site_url() ?>",
                "logo": "<?php echo alt_get_url_logo() ?>"
            }














        </script>

        <script type="application/ld+json" id="webSiteSchema">
            {
                "@context": "http://schema.org",
                "@type": "WebSite",
                "name": "<?php echo get_bloginfo('name'); ?>",
                "url": "<?php echo get_site_url() ?>"
            }
















        </script>


        <?php


    }
}

if (!function_exists('alt_get_schema_produto')) {
    function alt_get_schema_produto($prd)
    {

        global $product;

        $image_id  = $product->get_image_id();
        $image_url = wp_get_attachment_image_url( $image_id, 'full' );




        $titulo = $product->name;
        $imagem_principal = $image_url;
        $marca = alt_get_marca_modelo_tipo($product->id, 'marca');
        $preço = $product->get_price();


        $arrInfo = get_info_principal(true);


        $nome_loja = $arrInfo['nome_fantasia'];
        $telefone = $arrInfo['telefone'];
        $cidade = $arrInfo['cidade'];
        $estado = $arrInfo['estado'];
        $endereco = $arrInfo['endereco'];

        $url_veiculo = get_permalink( $product->id );
        $cor = alt_get_caracteristicas($product->id, 'alt_cor');
        ?>

        <script type="application/ld+json">
            [
                {
                    "@context": "http://schema.org",
                    "@type": "Car",
                    "vehicleIdentificationNumber": "JH4KA8251MC008351",
                    "name": "<?php echo $titulo; ?>",
                    "image": "<?php echo $imagem_principal; ?>",
                    "brand": {
                        "@type": "Organization",
                        "name": "<?php echo $marca; ?>"
                    },
                    "offers": {
                        "@type": "Offer",
                        "priceCurrency": "BRL",
                        "price": <?php echo $preço; ?>,
                        "availability": "http://schema.org/InStock",
                        "seller": {
                            "@type": "Organization",
                            "name": "<?php echo $nome_loja; ?>",
                            "telephone": "<?php echo $telefone; ?>",
                            "address": {
                                "@type": "PostalAddress",
                                "addressLocality": "<?php echo $cidade; ?>",
                                "addressRegion": "<?php echo $estado; ?>",
                                "streetAddress": "<?php echo $endereco; ?>"
                            },
                            "aggregateRating": {
                                "@type": "AggregateRating",
                                "ratingValue": 4,
                                "reviewCount": "36"
                            }
                        },
                        "itemCondition": "http://schema.org/UsedCondition",
                        "url": "<?php echo $url_veiculo; ?>",
                        "color": "<?php echo $cor; ?>"
                    }
                }
            ]



        </script>


        <?php



    }


    add_filter('woocommerce_before_single_product','alt_get_schema_produto', 1);

}