'; require_once __DIR__ . '/includes/functions.php'; $productId = $_GET['id'] ?? ''; if (!$productId) { header('Location: /shop.php'); exit; } // Get product $product = db()->fetch( "SELECT * FROM products WHERE product_id = :id AND is_active = 1", ['id' => $productId] ); if (!$product) { header('Location: /shop.php'); exit; } // Get product reviews $reviews = db()->fetchAll( "SELECT * FROM reviews WHERE product_id = :id AND is_approved = 1 ORDER BY created_at DESC LIMIT 10", ['id' => $productId] ); $avgRating = 0; $reviewCount = count($reviews); if ($reviewCount > 0) { $avgRating = array_sum(array_column($reviews, 'rating')) / $reviewCount; } // Get related products $relatedProducts = db()->fetchAll( "SELECT * FROM products WHERE category = :category AND product_id != :id AND is_active = 1 LIMIT 4", ['category' => $product['category'], 'id' => $productId] ); $images = json_decode($product['images'] ?? '[]', true); $mainImage = !empty($images) ? $images[0] : '/assets/images/placeholder-product.svg'; $salePrice = $product['sale_price']; $price = $product['price']; $inStock = $product['stock'] > 0; $displayPrice = $salePrice ?? $price; // SEO meta $categoryLabel = ucfirst($product['category'] ?? 'Coffee'); $metaTitle = $product['name'] . ' ' . $categoryLabel . " Coffee | Tom's Java Jive"; $metaDescription = truncate(strip_tags($product['description'] ?? ''), 155) ?: $product['name'] . ' flavored artisan coffee beans freshly roasted in Weatherford, TX. Available in whole bean and ground. Ships nationwide.'; $metaKeywords = strtolower($product['name']) . ' coffee, ' . strtolower($categoryLabel) . ' coffee, flavored coffee beans, artisan coffee, buy coffee online'; $canonicalUrl = 'https://tomsjavajive.com/product.php?id=' . $productId; $ogType = 'product'; $ogImage = (strpos($mainImage, 'http') === 0) ? $mainImage : 'https://tomsjavajive.com' . $mainImage; // Structured data — Product schema $productSchemaData = [ '@context' => 'https://schema.org', '@type' => 'Product', 'name' => $product['name'] . ' ' . $categoryLabel . ' Coffee', 'url' => $canonicalUrl, 'image' => $ogImage, 'description' => $metaDescription, 'brand' => ['@type' => 'Brand', 'name' => "Tom's Java Jive"], 'offers' => [ '@type' => 'Offer', 'priceCurrency' => 'USD', 'price' => number_format((float) $displayPrice, 2, '.', ''), 'priceValidUntil' => date('Y-12-31', strtotime('+1 year')), 'availability' => $inStock ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock', 'url' => $canonicalUrl, 'seller' => ['@type' => 'Organization', 'name' => "Tom's Java Jive"], 'shippingDetails' => [ '@type' => 'OfferShippingDetails', 'shippingRate' => ['@type' => 'MonetaryAmount', 'value' => '5.99', 'currency' => 'USD'], 'shippingDestination'=> ['@type' => 'DefinedRegion', 'addressCountry' => 'US'], 'deliveryTime' => [ '@type' => 'ShippingDeliveryTime', 'handlingTime' => ['@type' => 'QuantitativeValue', 'minValue' => 1, 'maxValue' => 2, 'unitCode' => 'DAY'], 'transitTime' => ['@type' => 'QuantitativeValue', 'minValue' => 3, 'maxValue' => 7, 'unitCode' => 'DAY'], ], ], 'hasMerchantReturnPolicy' => [ '@type' => 'MerchantReturnPolicy', 'applicableCountry' => 'US', 'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow', 'merchantReturnDays' => 30, 'returnMethod' => 'https://schema.org/ReturnByMail', 'returnFees' => 'https://schema.org/FreeReturn', 'returnPolicyLink' => 'https://tomsjavajive.com/returns.php', ], ], ]; if ($reviewCount > 0) { $productSchemaData['aggregateRating'] = [ '@type' => 'AggregateRating', 'ratingValue' => round($avgRating, 1), 'reviewCount' => $reviewCount, 'bestRating' => 5, 'worstRating' => 1, ]; } $productSchema = json_encode($productSchemaData, JSON_UNESCAPED_SLASHES); // Breadcrumbs $breadcrumbs = [ ['name' => 'Home', 'url' => 'https://tomsjavajive.com/'], ['name' => 'Shop', 'url' => 'https://tomsjavajive.com/shop.php'], ['name' => $product['name'], 'url' => $canonicalUrl], ]; require_once __DIR__ . '/includes/header.php'; ?>
<?= htmlspecialchars($product['name']) ?>
1): ?>
$img): ?> Product image <?= $index + 1 ?>

0): ?>
( reviews)
Save %

In Stock - Only left! Out of Stock

Description

Product Details

SKU
Weight oz
Category

Customer Reviews

Verified Purchase

No reviews yet. Be the first to review this product!

Related Products