$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 );
Pembe Kuvars Doğal Taş Takılar - Moony Stone
“Lapis Lazuli Doğal Taş Metal Kolye” sepetinize eklendi.
Sepetim
“Ametrin Doğal Taş Dizi (6mm)” sepetinize eklendi.
Sepetim
“Kare Model Gümüş Kral Zincir Kolye” sepetinize eklendi.
Sepetim
“Yakut Doğal Taş Faset Kesim Dizi (7mm)” sepetinize eklendi.
Sepetim
“Şekilsiz Orijinal Okyanus İnci Gerdanlık Kolye (6-7mm)” sepetinize eklendi.
Sepetim
“Sitrin Doğal Taş Metal Kolye” sepetinize eklendi.
Sepetim
“Pembe Kuvars Doğal Taş Dizi (10mm)” sepetinize eklendi.
Sepetim
“Pembe Kuvars Kalp Doğal Taş Dizi (15mm)” sepetinize eklendi.
Sepetim
“Yeşil Kuvars Doğal Taş Dizi” sepetinize eklendi.
Sepetim
“Dumanlı Kuvars Doğal Taş Metal Kolye” sepetinize eklendi.
Sepetim
“Lapis Lazuli Doğal Taş Dizi (8mm)” sepetinize eklendi.
Sepetim
“Pirit Doğal Taş Dizi (10mm)” sepetinize eklendi.
Sepetim
“Özel Kalite Zebercet,Garnet ve Yakut Doğal Taş Gümüş Gold Bayan Kolye” sepetinize eklendi.
Sepetim
“Orijinal Sitrin Taşı 925 Ayar Gümüş Tasarımlı Bayan Küpe” sepetinize eklendi.
Sepetim
“Özel Selestit Doğal Taş Ham Parça” sepetinize eklendi.
Sepetim
“Ateş Akik Doğal Taş Rondel Bileklik (8mm)” sepetinize eklendi.
Sepetim
“Yakut Doğal Taş Gümüş Unisex Yüzük (10ct)” sepetinize eklendi.
Sepetim
“Florit Doğal Taş Çelik Bileklik” sepetinize eklendi.
Sepetim
“AA Kalite Labradorit Doğal Taş Dizi (8mm)” sepetinize eklendi.
Sepetim
“Kaplangözü Doğal Taş Metal Kolye” sepetinize eklendi.
Sepetim
“Aventurin Doğal Taş Kolye Ucu” sepetinize eklendi.
Sepetim
“Florit Doğal Taş Vogel Pandül (Sarkaç)” sepetinize eklendi.
Sepetim
“Labradorit Doğal Taş Obelisk Parça” sepetinize eklendi.
Sepetim
“Güneş Taşı Doğal Taş Kesimli Arpa Dizi (6x8mm)” sepetinize eklendi.
Sepetim
“Unakit Doğal Taş Dizi (8mm)” sepetinize eklendi.
Sepetim
“Lapis Lazuli Doğal Taş Metal Kolye” sepetinize eklendi.
Sepetim
“Su Yolu Onix Taşı Unisex Gümüş Bileklik (3mm)” sepetinize eklendi.
Sepetim
“Tibet Akik Doğal Taş Bileklik (10mm)” sepetinize eklendi.
Sepetim
“Özel Herkimer Diamond (Elmas) Doğal Taş Bileklik (11-12mm)” sepetinize eklendi.
Sepetim
“Akuamarin Doğal Taş Dizi (8x12mm Yassı Kesim)” sepetinize eklendi.
Sepetim
“6A+ Kalite Lapis Lazuli Doğal Taş Bileklik (7-8mm)” sepetinize eklendi.
Sepetim
“Orijinal Sertifikalı Ice Cut Taşı 925 Ayar Gümüş Tasarımlı Bayan Kolye” sepetinize eklendi.
Sepetim
“5A+Kalite Ay Taşı Doğal Taş Bileklik (8mm)” sepetinize eklendi.
Sepetim
“7A+ Kalite Akuamarin Doğal Taş Rolex Bileklik” sepetinize eklendi.
Sepetim
“8MM Akuamorganit Doğal Taş Dizi” sepetinize eklendi.
Sepetim
“2A Kalite Çiçek Desenli Florit Doğal Taş Dizi” sepetinize eklendi.
Sepetim
Ürün Kodu:
GKP-0018
₺33,44
Ürün Kodu:
DIZI8-0696
₺15,20
Ürün Kodu:
DIZI8-0695
₺10,73
Ürün Kodu:
DIZI8-0694
₺8,49
Ürün Kodu:
DIZI8-0693
₺6,71
Ürün Kodu:
GB00171
₺140,07
Ürün Kodu:
PNDL-026
₺5,67
Ürün Kodu:
PNDL-017
₺5,67
Ürün Kodu:
DTH-0223
₺113,49