/*
 Theme Name:   Woodmart Child
 Description:  Woodmart Child Theme
 Author:       XTemos
 Author URI:   http://xtemos.com
 Template:     woodmart
 Version:      1.0.0
 Text Domain:  woodmart
*/

<?php
// WoodMart Child Tema için functions.php

// WordPress giriş sayfası logosunu değiştirme (Eğer daha önce tanımlanmadıysa)
if (!function_exists('custom_loginlogo')) {
    function custom_loginlogo() {
        echo '<style type="text/css"> 
        body.login div#login h1 a {
            background-image: url(https://www.3dprintermarketi.com/wp-content/uploads/2024/06/3d-printer-market.svg);
            background-size: 200px;
            width: 200px;
            height:77px;
        }
        </style>';
    }
    add_action('login_head', 'custom_loginlogo');
}

// Ürün sayfasına "2 Gün İçinde Kargoda" metni ekleme
if (!function_exists('add_shipping_text_to_product')) {
    function add_shipping_text_to_product() {
        echo '<p style="color: green; font-weight: bold;">🚚 2 Gün İçinde Kargoda</p>';
    }
    add_action('woocommerce_single_product_summary', 'add_shipping_text_to_product', 20);
}

// Ürün kategorisi sayfalarına yapılandırılmış veri (Schema.org) ekleme
if (!function_exists('add_product_schema_to_category_pages')) {
    function add_product_schema_to_category_pages() {
        if (is_product_category()) {
            global $wp_query;
            $products = [];

            foreach ($wp_query->posts as $post) {
                $product = wc_get_product($post->ID);
                $products[] = [
                    "@type" => "Product",
                    "name" => $product->get_name(),
                    "image" => wp_get_attachment_url($product->get_image_id()),
                    "description" => wp_strip_all_tags($product->get_short_description()),
                    "sku" => $product->get_sku(),
                    "brand" => [
                        "@type" => "Brand",
                        "name" => get_post_meta($post->ID, '_product_brand', true) ?: "Marka Belirtilmemiş"
                    ],
                    "offers" => [
                        "@type" => "Offer",
                        "priceCurrency" => get_woocommerce_currency(),
                        "price" => $product->get_price(),
                        "availability" => $product->is_in_stock() ? "https://schema.org/InStock" : "https://schema.org/OutOfStock",
                        "url" => get_permalink($post->ID)
                    ],
                    "aggregateRating" => [
                        "@type" => "AggregateRating",
                        "ratingValue" => $product->get_average_rating(),
                        "reviewCount" => $product->get_review_count()
                    ]
                ];
            }

            echo '<script type="application/ld+json">' . json_encode(["@context" => "https://schema.org", "@graph" => $products], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . '</script>';
        }
    }
    add_action('wp_head', 'add_product_schema_to_category_pages');
}

// Tema Destekleri (Mevcut Kodlarınızı Koruyarak Güncellendi)
if (!function_exists('woodmart_child_theme_setup')) {
    function woodmart_child_theme_setup() {
        add_theme_support('woocommerce');
        add_theme_support('post-thumbnails');
        add_theme_support('title-tag');
    }
    add_action('after_setup_theme', 'woodmart_child_theme_setup');
}

// WooCommerce Sepet Sayfasında Ürün Altındaki Kargo Bilgisi (Mevcut Kod)
if (!function_exists('custom_shipping_info_in_cart')) {
    function custom_shipping_info_in_cart($item_name, $cart_item, $cart_item_key) {
        return $item_name . '<br><span style="color: green; font-weight: bold;">🚚 Tahmini Teslimat: 2-3 İş Günü</span>';
    }
    add_filter('woocommerce_cart_item_name', 'custom_shipping_info_in_cart', 10, 3);
}
