['name' => 'Bagoft SipariÅŸleri', 'singular_name' => 'Bagoft SipariÅŸi'], 'public' => false, 'show_ui' => true, 'show_in_rest' => false, 'map_meta_cap' => false, 'capabilities' => [ 'edit_post' => 'manage_options', 'read_post' => 'manage_options', 'delete_post' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'read_private_posts' => 'manage_options', 'publish_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'delete_private_posts' => 'manage_options', 'delete_others_posts' => 'manage_options', 'create_posts' => 'do_not_allow', ], 'supports' => ['title', 'editor'], 'menu_icon' => 'dashicons-cart', ]); }); function bgft_cart_url() { $page = get_page_by_path('sepet'); return $page && $page->post_status === 'publish' ? get_permalink($page) : ''; } function bgft_cart_assets() { wp_enqueue_script('bgft-cart', plugins_url('sepet.js', __FILE__), [], '1.2.2', true); wp_enqueue_style('bgft-cart', plugins_url('sepet.css', __FILE__), [], '1.2.0'); } add_action('wp_enqueue_scripts', function () { $page = get_queried_object(); if (is_singular('urun') || ($page instanceof WP_Post && has_shortcode($page->post_content, 'bagoft_sepet'))) { bgft_cart_assets(); } }); add_shortcode('bagoft_sepete_ekle', function () { if (!is_singular('urun') || post_password_required(get_queried_object_id())) { return ''; } $url = bgft_cart_url(); if (!$url) { return ''; } $id = get_queried_object_id(); ob_start(); ?> Adet Sepete Ekle Sepeti Gör Sepeti kullanmak için tarayıcınızda JavaScript’i etkinleÅŸtirin. Sepetiniz boÅŸ. Ürün Ürün Kodu Adet İşlem Toplam adet 0 Teslimat ve iletiÅŸim bilgileri Ad Soyad Telefon İl İlçe Açık adres E-posta SipariÅŸ Talebini Gönder Koleksiyonda görünen ürün kodu <= 240) { update_post_meta($post_id, '_bgft_product_code', wp_slash($code)); } }); function bgft_cart_codes() { $raw = $_POST['ids'] ?? ''; $ids = is_string($raw) && strlen($raw) < 3000 ? json_decode(wp_unslash($raw), true) : null; if (!is_array($ids) || count($ids) > 100) { wp_send_json_error('Ürün kodları alınamadı.', 400); } $codes = []; foreach ($ids as $id) { if (!is_int($id) || $id < 1) { continue; } $product = get_post($id); if ($product && $product->post_type === 'urun' && $product->post_status === 'publish' && $product->post_password === '') { $gorseller = function_exists('bagoft_urun_gorselleri') ? bagoft_urun_gorselleri($id) : []; $ilk_gorsel = $gorseller[0] ?? []; $codes[$id] = [ 'code' => bgft_product_code($id), 'image' => $ilk_gorsel['sizes']['thumbnail'] ?? ($ilk_gorsel['url'] ?? ''), ]; } } wp_send_json_success((object) $codes); } function bgft_order_token() { nocache_headers(); wp_send_json_success(['nonce' => wp_create_nonce('bgft_order')]); } function bgft_order_submit() { if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || !check_ajax_referer('bgft_order', 'nonce', false)) { wp_send_json_error('Oturum doÄŸrulanamadı. Lütfen tekrar deneyin.', 403); } $fields = ['first_name' => ['Ad', 100], 'last_name' => ['Soyad', 100], 'phone' => ['Telefon', 40], 'province' => ['İl', 100], 'district' => ['İlçe', 100], 'address' => ['Açık adres', 1000], 'email' => ['E-posta', 254]]; $contact = []; foreach ($fields as $key => [$label, $limit]) { $raw = isset($_POST[$key]) && is_string($_POST[$key]) ? wp_unslash($_POST[$key]) : ''; $value = $key === 'address' ? sanitize_textarea_field($raw) : sanitize_text_field($raw); if ($value === '' || strlen($value) > $limit * 4 || ($key === 'email' && !is_email($value)) || ($key === 'phone' && strlen(preg_replace('/[^0-9]/', '', $value)) < 7)) { wp_send_json_error($label . ' alanını kontrol edin.', 400); } $contact[$key] = $value; } $raw_cart = isset($_POST['cart']) && is_string($_POST['cart']) ? wp_unslash($_POST['cart']) : ''; $cart = strlen($raw_cart) <= 12000 ? json_decode($raw_cart, true) : null; if (!is_array($cart) || !$cart || count($cart) > 100) { wp_send_json_error('Sepetinizde 1 ile 100 farklı ürün olmalı.', 400); } $total = 0; $rows = ''; foreach ($cart as $id => $quantity) { if (!is_int($id) || $id < 1 || !is_int($quantity) || $quantity < 1 || $quantity > 99999) { wp_send_json_error('Sepetteki ürün adetlerini kontrol edin.', 400); } $product = get_post($id); if (!$product || $product->post_type !== 'urun' || $product->post_status !== 'publish' || $product->post_password !== '') { wp_send_json_error('Sepetinizdeki bir ürün artık sipariÅŸe açık deÄŸil. Ürünü kaldırıp tekrar deneyin.', 400); } $rows .= '' . esc_html(get_the_title($id)) . '' . esc_html(bgft_product_code($id) ?: '—') . '' . $id . '' . $quantity . ''; $total += $quantity; } $body = ' Ürün Ürün Kodu Ürün ID Adet' . $rows . ' Toplam adet ' . $total . ' '; foreach ($fields as $key => [$label]) { $body .= ' ' . esc_html($label) . ' ' . nl2br(esc_html($contact[$key])) . ' '; } $order = wp_insert_post(wp_slash([ 'post_type' => 'bgft_order', 'post_status' => 'private', 'post_title' => 'SipariÅŸ • ' . current_time('Y-m-d H:i:s'), 'post_content' => $body, ]), true); if (is_wp_error($order) || !$order) { wp_send_json_error('SipariÅŸ kaydedilemedi. Lütfen tekrar deneyin.', 500); } $recipient = apply_filters('bgft_order_recipient', 'bagoftcanta@gmail.com'); $mail_sent = wp_mail($recipient, 'Bagoft sipariÅŸ talebi #' . $order, $body, [ 'Content-Type: text/html; charset=UTF-8', 'Reply-To: ' . $contact['email'], ]); update_post_meta($order, '_bgft_mail_status', $mail_sent ? 'accepted' : 'failed'); wp_send_json_success(['order' => $order]); } foreach (['wp_ajax_', 'wp_ajax_nopriv_'] as $prefix) { add_action($prefix . 'bgft_cart_codes', 'bgft_cart_codes'); add_action($prefix . 'bgft_order_token', 'bgft_order_token'); add_action($prefix . 'bgft_order_submit', 'bgft_order_submit'); } add_action('add_meta_boxes_bgft_order', function () { add_meta_box('bgft_mail_status', 'E-posta bildirimi', function ($order) { $status = get_post_meta($order->ID, '_bgft_mail_status', true); $messages = [ 'accepted' => 'WordPress bildirimi gönderim için kabul etti.', 'failed' => 'WordPress bildirimi gönderemedi. SipariÅŸ kayıtlı.', ]; echo ' ' . esc_html($messages[$status] ?? 'Bu sipariÅŸ için e-posta durumu kaydedilmemiÅŸ.') . ' '; }, 'bgft_order', 'side'); }); add_action('add_meta_boxes_bgft_order', function () { add_meta_box( 'bgft_whatsapp_buttons', 'WhatsApp ile paylaÅŸ', function ($order) { // Etiketleri ve numaraları kendi alıcılarına göre deÄŸiÅŸtir. // Numaraları ülke koduyla, + iÅŸareti ve boÅŸluk olmadan yaz. $recipients = [ 'SipariÅŸi paylaÅŸ' => '905425459628', ]; $to_text = static function ($html) { return trim(html_entity_decode( wp_strip_all_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8' )); }; $widths = [18, 10, 6, 5]; $format_row = static function ($values) use ($widths) { $columns = []; foreach ($widths as $index => $width) { preg_match_all('/.{1,' . $width . '}/us', $values[$index], $matches); $columns[] = $matches[0] ?: ['']; } $lines = []; $height = max(array_map('count', $columns)); for ($line = 0; $line < $height; $line++) { $parts = []; foreach ($widths as $index => $width) { $part = $columns[$index][$line] ?? ''; $length = preg_match_all('/./us', $part); $spaces = str_repeat(' ', max(0, $width - $length)); $parts[] = $index < 2 ? $part . $spaces : $spaces . $part; } $lines[] = implode(' | ', $parts); } return implode("\n", $lines); }; $details_html = $order->post_content; $product_rows = []; if (preg_match('~]*>.*?~is', $details_html, $table)) { preg_match_all('~]*>(.*?)~is', $table[0], $rows); foreach ($rows[1] as $row) { preg_match_all('~]*>(.*?)~is', $row, $cells); if (count($cells[1]) !== 4) { continue; } $values = array_map(static function ($cell) use ($to_text) { $text = preg_replace('/\s+/u', ' ', $to_text($cell)); return str_replace(chr(96), "'", $text); }, $cells[1]); $product_rows[] = $format_row($values); } if ($product_rows) { $details_html = str_replace($table[0], '', $details_html); } } $message = "bagoft sipariÅŸ talebi #{$order->ID}"; if ($product_rows) { $separator = implode('-+-', array_map(static function ($width) { return str_repeat('-', $width); }, $widths)); $header = $format_row(['Ürün', 'Ürün Kodu', 'ID', 'Adet']); $table_text = implode("\n" . $separator . "\n", array_merge([$header], $product_rows)); $monospace = str_repeat(chr(96), 3); $message .= "\n\n" . $monospace . $table_text . $monospace; } $details = $to_text(preg_replace( ['~~i', '~\s*]*>~i', '~~i', '~~i'], ["\n", ' | ', "\n", "\n\n"], $details_html )); if ($details !== '') { $message .= "\n\n" . $details; } foreach ($recipients as $label => $number) { if (!preg_match('/^[1-9][0-9]{7,14}$/D', $number)) { echo ' ' . esc_html($label . ' için numara girin.') . ' '; continue; } $url = 'https://wa.me/' . $number . '?text=' . rawurlencode($message); printf( ' %s ', esc_attr($url), esc_html($label . ' — WhatsApp’ı aç') ); } }, 'bgft_order', 'side' ); }); Sayfa bulunamadı – Bagoft

Sayfa bulunamadı

Aradığınız sayfa kaldırılmış, adı değiştirilmiş veya geçici olarak kullanılamıyor olabilir.

Ana sayfaya dön