$imgs = []; if ($id = $p->get_image_id()) { if ($u = wp_get_attachment_url($id)) $imgs[] = $u; } foreach ((array)$p->get_gallery_image_ids() as $gid) { if ($u = wp_get_attachment_url($gid)) $imgs[] = $u; } $imgs = array_values(array_unique($imgs)); /* Marka & GTIN/MPN */ // $brand_names = wp_get_post_terms($product_id, 'product_brand', ['fields' => 'names']); // Orijinali devre dışı bırakıldı // $brand = $brand_names ? ['@type' => 'Brand', 'name' => implode(', ', $brand_names)] : null; // Orijinali devre dışı bırakıldı $brand = ['@type' => 'Brand', 'name' => 'Safir Taş Evi']; // YENİ: Sabit marka $meta = function($k) use ($product_id){ return get_post_meta($product_id, $k, true) ?: null; }; $gtin_raw = $meta('_yoast_wpseo_product_gtin13') ?: $meta('_yoast_wpseo_product_gtin14') ?: $meta('_yoast_wpseo_product_gtin12') ?: $meta('_yoast_wpseo_product_gtin8') ?: $meta('_yoast_wpseo_product_isbn'); $mpn = $meta('_yoast_wpseo_product_mpn'); $gtin_digits = $gtin_raw ? preg_replace('/\D+/', '', (string)$gtin_raw) : ''; $gtin_key = null; if ($gtin_digits !== '') { $len = strlen($gtin_digits); if ($len === 8) $gtin_key = 'gtin8'; elseif ($len === 12) $gtin_key = 'gtin12'; elseif ($len === 13) $gtin_key = 'gtin13'; elseif ($len === 14) $gtin_key = 'gtin14'; } /* === ATTRIBUTES (tekil okuma) === */ $tax_color = 'pa_tas-rengi'; // YENİ $tax_gender = 'pa_cinsiyet'; // YENİ // color: en fazla 3 isim, "/" ile birleştir $color_names = wc_get_product_terms($product_id, $tax_color, ['fields'=>'names']); if (empty($color_names)) { $raw = $p->get_attribute($tax_color); if ($raw) { $parts = preg_split('/[,\|\/]+/u', $raw); $color_names = array_values(array_filter(array_map('trim', (array)$parts))); } } if (!empty($color_names)) { $color_names = array_values(array_filter($color_names)); $color_str = implode('/', array_slice($color_names, 0, 3)); // "Red/Gray/White" } else { $color_str = null; } // gender: tek slug $gender_terms = wc_get_product_terms($product_id, $tax_gender, ['fields'=>'slugs']); $gender = $gender_terms ? strtolower($gender_terms[0]) : null; // if ($gender && !in_array($gender, ['male','female','unisex'], true)) $gender = null; // YENİ: Talep üzerine kontrol kaldırıldı // age_group: tüm ürünlerde adult $age_group = 'adult'; /* Çekirdek veri */ $data = [ '@context' => 'https://schema.org/', '@type' => 'Product', '@id' => $url, 'url' => $url, 'inLanguage' => $lang, 'name' => $title, 'description' => $desc, 'sku' => $p->get_sku() ?: null, 'image' => $imgs ?: null, 'brand' => $brand, ]; // color → Product.color if ($color_str) $data['color'] = $color_str; // audience → gender + age_group $aud = ['@type'=>'PeopleAudience', 'suggestedAge'=>$age_group]; if ($gender) $aud['suggestedGender'] = $gender; $data['audience'] = $aud; /* Fiyat */ $currency = get_woocommerce_currency(); $dec = (int) wc_get_price_decimals(); if ($p->is_type('variable')) { $vals = []; foreach ($p->get_children() as $vid) { $v = wc_get_product($vid); if (!$v || !$v->is_purchasable()) continue; $price = $v->get_price(); if ($price === '' || $price === null) continue; $vals[] = (float) $price; } if ($vals) { $data['offers'] = [ '@type' => 'AggregateOffer', 'url' => $url, 'lowPrice' => number_format(min($vals), $dec, '.', ''), 'highPrice' => number_format(max($vals), $dec, '.', ''), 'priceCurrency' => $currency, 'offerCount' => count($vals), 'availability' => $p->is_in_stock() ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock', 'itemCondition' => 'https://schema.org/NewCondition', ]; } } else { $final = $p->get_price(); if ($final !== '' && $final !== null) { $data['offers'] = [ '@type' => 'Offer', 'url' => $url, 'price' => number_format($final, $dec, '.', ''), 'priceCurrency' => $currency, 'availability' => $p->is_in_stock() ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock', 'itemCondition' => 'https://schema.org/NewCondition', ]; } } if ($gtin_key) $data[$gtin_key] = $gtin_digits; if ($mpn) $data['mpn'] = $mpn; echo ''; }, 99); add_filter( 'woocommerce_cart_ready_to_calc_shipping', 'disable_shipping_calc_on_cart', 99 ); function disable_shipping_calc_on_cart( $show_shipping ) { if ( is_cart() ) { return false; } return $show_shipping; } add_filter( 'posts_clauses', function( $clauses, $query ) { if ( is_admin() || 'product_query' !== $query->get( 'wc_query' ) ) { return $clauses; } global $wpdb; $lookup_table = $wpdb->prefix . 'wc_product_meta_lookup'; if ( false === strpos( $clauses['join'], 'wc_stock_sort_lookup' ) ) { $clauses['join'] .= " LEFT JOIN {$lookup_table} AS wc_stock_sort_lookup ON {$wpdb->posts}.ID = wc_stock_sort_lookup.product_id"; } $stock_order = "CASE WHEN wc_stock_sort_lookup.stock_status = 'outofstock' THEN 1 ELSE 0 END ASC"; if ( false === strpos( $clauses['orderby'], 'wc_stock_sort_lookup.stock_status' ) ) { $clauses['orderby'] = $stock_order . ', ' . $clauses['orderby']; } return $clauses; }, 9999, 2 );