File: /var/www/html/TBbargain/wp-content/themes/Tbbargain/single.php
<?php /* Template Name: Product Details Page */
get_header();
?>
<!-- Popup Form -->
<!-- <div id="report-expired-popup" class="report-popup" style="display: none;">
<div class="popup-content">
<h2>Report as Expired</h2>
<form id="report-expired-form">
<label for="email">Enter your Email ID:</label>
<input type="email" id="email" name="email" required>
<input type="hidden" id="deal-id" name="deal_id" value="<?php echo get_the_ID(); ?>">
<button type="submit">Submit</button>
</form>
<button id="close-popup">Close</button>
</div>
</div> -->
<div class="modal expiry-modal fade" id="expiryModal" tabindex="-1" aria-labelledby="expiryModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="top-blk">
<div class="icon-blk">
<span class="icon"><img src="<?php echo get_template_directory_uri(); ?>/img/expired-icon.svg" alt=""></span>
</div>
<div class="title-lg">Report This Deal As Expired?</div>
<p class="deal-para">This Will Send The Deal To Our Staff For Review.</p>
</div>
<div class="modal-search-blk">
<div class="email-wrap">
<form id="report-expired-form">
<input type="email" class="txt" id="email" name="email" placeholder="Enter Your Mail ID Here" fdprocessedid="gu7lxa" autocomplete="off">
<input type="hidden" id="deal-id" name="deal_id" value="<?php echo get_the_ID(); ?>">
<button class="button" type="submit" fdprocessedid="m8x5">
Send Now <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" data-name="vuesax/linear/arrow-right" viewBox="0 0 24 24">
<g fill="none" stroke="#223158" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" data-name="Group 998">
<path d="M14.43 5.93 20.5 12l-6.07 6.07"></path>
<path d="M3.5 12h16.83" data-name="Vector"></path>
</g>
</svg>
</button>
</form>
</div>
</div>
<center><span id="response-message"></span></center>
</div>
</div>
</div>
</div>
<section class="banner sub-bnr-dtl">
<?php
// Get the current post ID
$post_id = get_the_ID();
$product_id = get_the_ID();
echo $categories = get_the_terms($post_id, 'category');
if (!empty($categories) && !is_wp_error($categories)) {
// Initialize variables for category and subcategory
$main_category = null;
$subcategories = [];
// Loop through the categories
foreach ($categories as $category) {
// Check if the category has a parent
if ($category->parent == 0) {
$main_category = $category; // Top-level category
} else {
$subcategories[] = $category; // Subcategories
}
}
// Display the main category
if ($main_category) {
echo '<h3>Main Category: ' . esc_html($main_category->name) . '</h3>';
}
}
// Fetch product details
$title = get_field('title', $post_id);
$breadcrumb_category = get_field('category', $post_id); // Assuming 'category' field exists
$features_list = get_field('features_list', $post_id); // Assuming it's an array
$product = get_post($post_id);
if ($product && $product->post_type === 'custom_product') {
// Custom fields
$deal_badge = get_field('deal_badge', $product_id);
$carousel_images = get_field('carousel_images', $product_id);
//------------------------------------------------------------------
$vendors = get_field('vendors');
$vendor_term = get_term_by('name', $vendors, 'product_category');
if ($vendor_term) {
$category_id = $vendor_term->term_id; // Get the category ID
$category_icon = get_term_meta($category_id, '_category_icon', true);
}
//-----------------------------------------------------------------------
$title = get_field('title', $product_id);
$description = get_field('description', $product_id);
$crossprice = get_field('crossprice', $product_id);
$discounted_price = get_field('discounted_price', $product_id);
$deal_end_date = get_field('deal_end_date', $product_id);
$deal_link = get_field('deal_link', $product_id);
// Retrieve image IDs
$image_ids = get_post_meta($product_id, '_product_image_ids', true);
$image_ids = $image_ids ? explode(',', $image_ids) : [];
$expired = get_field('expired');
$expired_value = maybe_unserialize($expired);
// Calculate discount percentage
$discount_percent = 0;
if ($crossprice > $discounted_price && $crossprice > 0) {
$discount_percent = round((($crossprice - $discounted_price) / $crossprice) * 100);
}
$post_date = get_the_date('Y-m-d'); // The date the post was created
$post_date_timestamp = strtotime($post_date); // Convert to timestamp for calculations
// Get the last day of the current week (Sunday)
$last_day_of_week = strtotime('next Sunday'); // Get next Sunday (this will give you the last day of the current week)
// Calculate the difference in days between the post date and the last day of the current week
$date_diff = floor(($last_day_of_week - $post_date_timestamp) / (60 * 60 * 24)); // Difference in days
?>
<div class="breadcrumb">
<div class="container custom-container">
<a class="nav-link" href="<?php echo home_url(); ?>">Home</a>
<!-- <a class="nav-link" href="#"><?php echo esc_html($breadcrumb_category); ?></a> -->
<a class="nav-link" href="#"><?php echo esc_html($title); ?> Details</a>
</div>
</div>
<div class="container custom-container">
<div class="txt">
<h2 class="title"><?php echo esc_html($title); ?></h2>
<?php if (!empty($features_list)) : ?>
<ul class="features-list">
<?php foreach ($features_list as $feature) : ?>
<li><?php echo esc_html($feature); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
</section>
<section class="dtl-blk">
<div class="container custom-container">
<div class="dtl-pro-wrp">
<?php
$image_ids = get_post_meta(get_the_ID(), '_product_image_ids', true);
$image_ids = $image_ids ? explode(',', $image_ids) : [];
?>
<div class="lft">
<?php if (is_array($expired_value) && isset($expired_value[0]) && $expired_value[0] === 'Expired') {
?>
<div class="deal-badge hot">
<img src="<?php echo get_template_directory_uri(); ?>/img/deal-tag.svg" alt="" class="icon">
<div class="txt">Expired</div>
</div>
<?php } else {
if($date_diff<=7){
?>
<div class="deal-badge new">
<img src="<?php echo get_template_directory_uri(); ?>/img/deal-tag.svg" alt="" class="icon">
<div class="txt">New Deal</div>
</div>
<?php } } ?>
<?php if (!empty($image_ids)): ?>
<!-- Display the first image as the left thumbnail -->
<img src="<?php echo wp_get_attachment_url($image_ids[0]); ?>" alt="Product Thumbnail">
<?php else: ?>
<img src="<?php echo get_template_directory_uri(); ?>/img/thumb-galaxy.png" alt="Default Thumbnail">
<?php endif; ?>
</div>
<div class="rt-blks">
<?php
// Loop through the image IDs to display each image
foreach ($image_ids as $key => $image_id):
// Skip the first image as it is displayed in the left thumbnail
if ($key === 0) continue;
?>
<div class="rt-col <?php echo $key === 1 ? 'center' : ''; ?>">
<img src="<?php echo wp_get_attachment_url($image_id); ?>" alt="Product Image <?php echo $key; ?>">
</div>
<?php endforeach; ?>
<?php if (empty($image_ids)): ?>
<!-- Default images in case no image IDs are set -->
<div class="rt-col center">
<img src="<?php echo get_template_directory_uri(); ?>/img/s-ultra-1.png" alt="Default Image 1">
</div>
<div class="rt-col">
<img src="<?php echo get_template_directory_uri(); ?>/img/s-ultra-2.png" alt="Default Image 2">
</div>
<div class="rt-col">
<img src="<?php echo get_template_directory_uri(); ?>/img/s-ultra-3.png" alt="Default Image 3">
</div>
<div class="rt-col">
<img src="<?php echo get_template_directory_uri(); ?>/img/usb-thumb.png" alt="Default Image 4">
</div>
<?php endif; ?>
</div>
</div>
<div class="dtl-info-wrp">
<div class="info-rt">
<div class="pro-logo">
<?php if ($vendor_term) { if ($category_icon) : ?>
<img src="<?php echo esc_url($category_icon); ?>" alt="" class="logo">
<?php endif; } ?>
</div>
<div class="price">
<span class="large">$ <?php echo esc_html($discounted_price); ?></span><span class="cross">$ <?php echo esc_html($crossprice); ?></span>
</div>
<div class="offer">
<div class="off"><img src="<?php echo get_template_directory_uri(); ?>/img/offer-white.svg" alt=""> <?php echo esc_html($discount_percent); ?>% Off</div>
</div>
</div>
<div class="offer-btn-blk">
<button class="btn btn-expired" data-bs-toggle="modal" data-bs-target="#expiryModal">Expired?</button>
<a href="<?php echo esc_html($deal_link); ?>" class="get-deal-btn" target="_blank">
<span>Get Deal</span> <img src="<?php echo get_template_directory_uri(); ?>/img/get-deal.svg" alt="">
</a>
</div>
</div>
<div class="dtls-content">
<div class="title">Product Details</div>
<div class="dtl-content-list">
<div class="listing-feature"><?php echo wp_kses_post($description); ?></div>
</div>
</div>
</section>
<?php } ?>
<section class="all-deal-wrap dtl-list">
<div class="container custom-container">
<div class="row">
<div class="col-lg-12">
<h2 class="title">Suggested Products</h2>
</div>
<?php
// Loop through product deals
$args = array(
'post_type' => 'custom_product',
'posts_per_page' => 8
);
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
// Custom fields
$deal_badge = get_field('deal_badge');
$carousel_images = get_field('carousel_images');
//------------------------------------------------------------------
$vendors = get_field('vendors');
$vendor_term = get_term_by('name', $vendors, 'product_category');
if ($vendor_term) {
$category_id = $vendor_term->term_id; // Get the category ID
$category_icon = get_term_meta($category_id, '_category_icon', true);
}
//-----------------------------------------------------------------------
$subtitle = get_field('title');
$description = get_field('description');
$crossprice = get_field('crossprice');
$discounted_price = get_field('discounted_price');
$discount_percent = get_field('discount_percent');
$deal_end_date = get_field('deal_end_date');
$image_ids = get_post_meta(get_the_ID(), '_product_image_ids', true);
$image_ids = $image_ids ? explode(',', $image_ids) : [];
$expired = get_field('expired');
$expired_value = maybe_unserialize($expired);
$discount_percent = 0;
if ($crossprice > $discounted_price && $crossprice > 0) {
$discount_percent = round((($crossprice - $discounted_price) / $crossprice) * 100);
}
$post_date = get_the_date('Y-m-d'); // The date the post was created
$post_date_timestamp = strtotime($post_date); // Convert to timestamp for calculations
// Get the last day of the current week (Sunday)
$last_day_of_week = strtotime('next Sunday'); // Get next Sunday (this will give you the last day of the current week)
// Calculate the difference in days between the post date and the last day of the current week
$date_diff = floor(($last_day_of_week - $post_date_timestamp) / (60 * 60 * 24)); // Difference in days
?>
<div class="col-lg-3"><!-- card starts -->
<a href="<?php echo get_permalink(); ?>" class="card-row-wrap">
<div class="img-carouel-wrap">
<?php if (is_array($expired_value) && isset($expired_value[0]) && $expired_value[0] === 'Expired') {
?>
<div class="deal-badge hot">
<img src="<?php echo get_template_directory_uri(); ?>/img/deal-tag.svg" alt="" class="icon">
<div class="txt">Expired</div>
</div>
<?php } else {
if($date_diff<=7){
?>
<div class="deal-badge new">
<img src="<?php echo get_template_directory_uri(); ?>/img/deal-tag.svg" alt="" class="icon">
<div class="txt">New Deal</div>
</div>
<?php } } ?>
<?php if (!empty($image_ids)) : ?>
<div class="thumbImgSlider">
<?php foreach ($image_ids as $id) : ?>
<div>
<img src="<?php echo esc_url(wp_get_attachment_url($id)); ?>" alt="Product Image" style="max-width: 100%; height: auto;">
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="content-wrap">
<?php if ($vendor_term) { if ($category_icon) : ?>
<img src="<?php echo esc_url($category_icon); ?>" alt="" class="logo">
<?php endif; } ?>
<h2 class="sub-title"><?php echo esc_html($subtitle); ?></h2>
<!-- <p class="sub-para"><?php echo esc_html($description); ?></p> -->
<div class="price">
<span class="large">$<?php echo esc_html($discounted_price); ?></span>
<span class="cross">$<?php echo esc_html($crossprice); ?></span>
</div>
<div class="offer">
<div class="off">
<img src="<?php echo get_template_directory_uri(); ?>/img/offer-white.svg" alt="">
<?php echo esc_html($discount_percent); ?>% Off
</div>
<div class="end"><?php $date_parts = explode('/', $deal_end_date); // Split the date by '/'
if (count($date_parts) === 3) {
$formatted_date = $date_parts[1] . '/' . $date_parts[0] . '/' . $date_parts[2]; // Rearrange to mm/dd/yyyy
echo esc_html($formatted_date);
} ?></div>
</div>
</div>
</a><!-- card ends -->
</div>
<?php
endwhile;
wp_reset_postdata();
else :
echo '<p>No product deals found.</p>';
endif;
?>
</div>
</div>
<?php if ($query->have_posts()) : ?>
<div class="btn-blk">
<!-- <a href="#" class="view-all" id="load-more">View All</a> -->
<button class="view-all" id="load-more">View All</button>
</div>
<?php endif; ?>
</section>
<section class="signup-wrap">
<div class="container custom-container">
<div class="bg-wrap align-items-cente d-flex">
<div class="row align-items-center">
<div class="col-lg-6">
<div class="content">
<h2 class="title">
Sign Up For Exclusive Offers And Updates!
</h2>
<p class="para">Stay ahead of the curve with our exclusive newsletter!</p>
</div>
</div>
<div class="col-lg-6">
<div class="email-wrap">
<form class="footer-form" id="subscribe-form1" >
<input type="email" name="emailid" class="txt" placeholder="Enter your email" required autocomplete="off">
<button class="button" id="subscribe-button1">
Subscribe <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
data-name="vuesax/linear/arrow-right" viewBox="0 0 24 24">
<g fill="none" stroke="#223158" stroke-linecap="round" stroke-linejoin="round"
stroke-width="1.5" data-name="Group 998">
<path d="M14.43 5.93 20.5 12l-6.07 6.07" />
<path d="M3.5 12h16.83" data-name="Vector" />
</g>
</svg>
</button>
</form>
</div>
<div id="response-message1" style="margin-top: 10px;"></div>
</div>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>