/*
Theme Name: Porto Child
Theme URI: https://www.portotheme.com/wordpress/porto
Author: P-THEMES
Author URI: https://www.portotheme.com/
Description: Porto Responsive WordPress + eCommerce Theme.
Version: 1.1
Template: porto
License: Commercial
License URI: http://themeforest.net/licenses/regular_extended
Tags: woocommerce, corporate, ecommerce, responsive, blue, black, green, white, light, dark, red, two-columns, three-columns, four-columns, left-sidebar, right-sidebar, fixed-layout, responsive-layout, custom-menu, editor-style, featured-images, flexible-header, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, translation-ready, accessibility-ready
*/

/*************** ADD YOUR CUSTOM CSS HERE  ***************/


// WPC Buy Now butonunu tamamen özelleştir ve WhatsApp'a yönlendir
add_action('wp', function () {
    // Mevcut Buy Now butonunu kaldır
    remove_action('woocommerce_after_add_to_cart_button', 'wpcbn_buy_now_button_html', 20);
    remove_action('woocommerce_after_add_to_cart_form', 'wpcbn_buy_now_button_html', 20);
    remove_action('woocommerce_after_shop_loop_item', 'wpcbn_buy_now_button_html', 20);

    // Yeni Buy Now butonu ekle
    add_action('woocommerce_after_add_to_cart_button', function () {
        global $product;
        $product_name = $product->get_name();
        $product_url  = get_permalink($product->get_id());
        
        // WhatsApp numaranı buraya yaz (90 ile başlayacak)
        $whatsapp = '905321234567'; 
        $message = rawurlencode("Merhaba, bu ürünle ilgileniyorum:\n{$product_name}\n{$product_url}");
        $wa_url = "https://wa.me/{$whatsapp}?text={$message}";

        echo '<a href="' . esc_url($wa_url) . '" target="_blank" rel="noopener" class="button alt whatsapp-buy-now" style="background:#25D366;border:none;">WhatsApp ile Sipariş Ver</a>';
    }, 20);
});


// Related Products başlığını Türkçeleştir
add_filter('gettext', 'custom_translate_related_products', 20, 3);
function custom_translate_related_products($translated, $text, $domain) {
    if ($text === 'Related products') {
        $translated = 'Benzer Ürünler'; // Burayı istediğiniz gibi değiştirin
    }
    return $translated;
}

add_action( 'wp_enqueue_scripts', function() {
    // Elementor Lightbox'ı devre dışı bırak
    wp_dequeue_script( 'elementor-frontend' );
    wp_dequeue_style( 'elementor-frontend' );
}, 20 );
