| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- if (!defined('WPINC')) {
- die;
- }
- /** @var WC_Cart|null $cart */
- /** @var int $product_id */
- // Collect cart lines that belong to this product and carry an FPP file reference.
- $lines = array();
- $subtotal = 0.0;
- if ($cart && $cart instanceof WC_Cart) {
- foreach ($cart->get_cart() as $cart_item_key => $item) {
- if (empty($item['studiou_fpp_file_record_id'])) {
- continue;
- }
- $line_product_id = (int) ($item['product_id'] ?? 0);
- if ($line_product_id !== (int) $product_id) {
- continue;
- }
- $lines[] = array(
- 'key' => $cart_item_key,
- 'item' => $item,
- );
- $subtotal += (float) ($item['line_total'] ?? 0.0) + (float) ($item['line_tax'] ?? 0.0);
- }
- }
- ?>
- <div class="studiou-fpp-overview" id="studiou-fpp-overview"
- data-product-id="<?php echo esc_attr($product_id); ?>"
- <?php echo empty($lines) ? ' style="display:none;"' : ''; ?>>
- <h3 class="studiou-fpp-overview-title"><?php esc_html_e('Your order', 'studiou-wc-free-photo-product'); ?></h3>
- <div class="studiou-fpp-overview-lines" id="studiou-fpp-overview-lines">
- <?php if (!empty($lines)) : ?>
- <?php foreach ($lines as $line) :
- $item = $line['item'];
- $key = $line['key'];
- $thumb = $item['studiou_fpp_thumb_url'] ?? '';
- $preview = '';
- if (!empty($item['studiou_fpp_attachment_id'])) {
- $pv = wp_get_attachment_image_src((int) $item['studiou_fpp_attachment_id'], 'woocommerce_single');
- if ($pv) { $preview = $pv[0]; }
- }
- if (!$preview) { $preview = $thumb; }
- $name = $item['studiou_fpp_file_name'] ?? '';
- $qty = (int) ($item['quantity'] ?? 0);
- $variation = wc_get_product($item['variation_id'] ?? 0);
- $variant_label = '';
- if ($variation) {
- $bits = array();
- foreach ($variation->get_attributes() as $k => $v) {
- if ($v === '') continue;
- $tax = str_replace('attribute_', '', $k);
- $term = taxonomy_exists($tax) ? get_term_by('slug', $v, $tax) : null;
- $raw = $term ? $term->name : urldecode((string) $v);
- $bits[] = html_entity_decode($raw, ENT_QUOTES | ENT_HTML5, 'UTF-8');
- }
- $variant_label = implode(' / ', $bits);
- }
- $unit_price = $qty > 0 ? (float) $item['line_subtotal'] / $qty : 0.0;
- $line_total = (float) ($item['line_total'] ?? 0.0);
- $base_price = $variation ? (float) get_post_meta($variation->get_id(), '_price', true) : 0.0;
- $discount_pct = ($base_price > 0 && $unit_price < $base_price)
- ? (int) round((1 - ($unit_price / $base_price)) * 100)
- : 0;
- $remove_url = wp_nonce_url(
- add_query_arg('studiou-fpp-remove-line', $key, get_permalink($product_id)),
- 'studiou-fpp-remove-line'
- );
- ?>
- <div class="studiou-fpp-overview-line" data-cart-item-key="<?php echo esc_attr($key); ?>">
- <?php if ($thumb) : ?>
- <img class="studiou-fpp-overview-thumb" src="<?php echo esc_url($thumb); ?>" alt="<?php echo esc_attr($name); ?>" data-preview-url="<?php echo esc_url($preview); ?>" data-file-name="<?php echo esc_attr($name); ?>" />
- <?php endif; ?>
- <div class="studiou-fpp-overview-body">
- <div class="studiou-fpp-overview-name-row">
- <div class="studiou-fpp-overview-name"><?php echo esc_html($name); ?></div>
- <button type="button" class="studiou-fpp-overview-enlarge"><?php esc_html_e('Enlarge', 'studiou-wc-free-photo-product'); ?></button>
- </div>
- <div class="studiou-fpp-overview-variant"><?php echo esc_html($variant_label); ?></div>
- <div class="studiou-fpp-overview-meta">
- <span class="studiou-fpp-overview-qty"><?php echo esc_html(sprintf(__('Qty %d', 'studiou-wc-free-photo-product'), $qty)); ?></span>
- <span class="studiou-fpp-overview-price"><?php echo wp_kses_post(wc_price($line_total)); ?></span>
- <?php if ($discount_pct > 0) : ?>
- <span class="studiou-fpp-overview-badge">−<?php echo esc_html($discount_pct); ?>%</span>
- <?php endif; ?>
- </div>
- </div>
- <a class="studiou-fpp-overview-remove" href="<?php echo esc_url($remove_url); ?>" title="<?php esc_attr_e('Remove', 'studiou-wc-free-photo-product'); ?>">×</a>
- </div>
- <?php endforeach; ?>
- <?php endif; ?>
- </div>
- <div class="studiou-fpp-overview-footer">
- <div class="studiou-fpp-overview-subtotal">
- <span class="studiou-fpp-overview-subtotal-label"><?php esc_html_e('Subtotal:', 'studiou-wc-free-photo-product'); ?></span>
- <span class="studiou-fpp-overview-subtotal-value"><?php echo wp_kses_post(wc_price($subtotal)); ?></span>
- </div>
- <a class="button studiou-fpp-overview-checkout" href="<?php echo esc_url(wc_get_checkout_url()); ?>">
- <?php esc_html_e('Go to checkout', 'studiou-wc-free-photo-product'); ?>
- </a>
- </div>
- </div>
|