• 01-08-2024, 23:06:35
    #10
    Developer
    @LaynThemes; @senturksun;

    sepete ekle butonu ile beraber:
    add_action('woocommerce_after_shop_loop_item', 'wc_whatsapp_button', 10 );
    add_action('woocommerce_after_add_to_cart_button', 'wc_whatsapp_button', 10 );
    function wc_whatsapp_button() {
        global $product;
        $button_text = 'WhatsApp';
        $phone = '905555555555';
        $text = urlencode($product->get_title().' Ürünü için yazıyorum');
        echo '<a target="_blank" class="btn btn-success" href="https://wa.me/'.$phone.'?text='.$text.'">WhatsApp</a>';
    }
    sepete ekle butonu olmadan:
    function woocommerce_template_loop_add_to_cart(){return wc_whatsapp_button();}
    function woocommerce_template_single_add_to_cart(){return wc_whatsapp_button();}
    function wc_whatsapp_button() {
        global $product;
        $button_text = 'WhatsApp';
        $phone = '905555555555';
        $text = urlencode($product->get_title().' Ürünü için yazıyorum');
        echo '<a target="_blank" class="btn btn-success" href="https://wa.me/'.$phone.'?text='.$text.'">WhatsApp</a>';
    }
    gibi olabilir
  • 10-02-2025, 01:44:30
    #11
    function woocommerce_template_loop_add_to_cart(){return wc_whatsapp_button();}
    function woocommerce_template_single_add_to_cart(){return wc_whatsapp_button();}
    function wc_whatsapp_button() {
    global $product;
    $button_text = 'WhatsApp ile Satın Al';
    $phone = '+905555555555';
    $product_title = $product->get_title();
    $product_link = get_permalink($product->get_id());
    $text = urlencode("Bu ürün için yazıyorum: $product_title - $product_link");
    
    echo '<div style="text-align: center; margin-top: 10px;">
    <a target="_blank" href="https://wa.me/'.$phone.'?text='.$text.'"
    style="display: inline-block; padding: 12px 20px; color: white; text-decoration: none; font-weight: bold;
    background-color: green; border-radius: 5px; border: none; box-shadow: none; text-align: center;">
    WhatsApp ile Satın Al
    </a>
    </div>';
    }
  • 10-02-2025, 18:02:59
    #12
    functions.php'ye:
    // 1. Ürün sayfalarında varsayılan "Sepete Ekle" butonunu kaldırıyoruz
    function remove_wc_add_to_cart_button() {
        if ( is_product() ) {
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        }
    }
    add_action( 'wp', 'remove_wc_add_to_cart_button' );
    
    // 2. Ürün detay sayfasına WhatsApp Sipariş Ver butonunu ekleyen fonksiyon
    function add_whatsapp_siparis_button() {
        if ( ! is_product() ) {
            return;
        }
    
        global $product;
        
        // Ürün bilgilerini alalım
        $product_id    = $product->get_id();
        $product_link  = get_permalink( $product_id );
        $product_title = $product->get_name();
    
        // Telefon numaranızı uluslararası formatta (ülke kodu ile, baştaki sıfır olmadan) girin
        $phone_number = '905XXXXXXXXX'; // Örneğin: Türkiye için "905XXXXXXXXX"
    
        // WhatsApp sipariş mesajını oluşturuyoruz (mesajı istediğiniz şekilde düzenleyebilirsiniz)
        $message = "Merhaba, ben {$product_title} ürününü sipariş etmek istiyorum. Ürün detayları: {$product_link}";
        
        // Mesajı URL uyumlu hale getiriyoruz
        $encoded_message = urlencode( $message );
        
        // WhatsApp API URL'sini oluşturuyoruz
        $whatsapp_url = "https://wa.me/{$phone_number}?text={$encoded_message}";
    
        // Buton HTML'ini oluşturuyoruz (CSS stillerini isteğinize göre ayarlayabilirsiniz)
        echo '<div class="whatsapp-siparis-wrapper" style="margin-top:20px;">';
        echo '<a href="' . esc_url( $whatsapp_url ) . '" target="_blank" class="whatsapp-siparis-btn" style="background:#25D366; color:#fff; padding:10px 20px; text-decoration:none; border-radius:5px;">WhatsApp Sipariş Ver</a>';
        echo '</div>';
    }
    add_action( 'woocommerce_single_product_summary', 'add_whatsapp_siparis_button', 31 );