58 lines
3.0 KiB
PHP
58 lines
3.0 KiB
PHP
<?php
|
||
/**
|
||
* Mini Cart — foundation (item count, items, subtotal, links, empty).
|
||
*
|
||
* @package XShop
|
||
*/
|
||
|
||
declare(strict_types=1);
|
||
|
||
defined('ABSPATH') || exit;
|
||
|
||
if (!function_exists('WC') || !WC()->cart) {
|
||
return;
|
||
}
|
||
$cart = WC()->cart;
|
||
$count = $cart->get_cart_contents_count();
|
||
$items = $cart->get_cart();
|
||
?>
|
||
<div class="xshop-mini-cart" data-xshop-mini-cart>
|
||
<div style="display:flex;justify-content:space-between;align-items:center;margin-block-end:var(--xshop-space-3)">
|
||
<strong><?php esc_html_e('Cart', 'xshop'); ?></strong>
|
||
<span class="xshop-mini-cart__count" aria-label="<?php echo esc_attr(sprintf(esc_html__('%d items', 'xshop'), $count)); ?>"><?php echo esc_html((string) $count); ?></span>
|
||
</div>
|
||
|
||
<?php if (empty($items)): ?>
|
||
<p class="xshop-mini-cart__empty"><?php esc_html_e('Your cart is empty.', 'xshop'); ?></p>
|
||
<a href="<?php echo esc_url(wc_get_page_permalink('shop')); ?>" class="xshop-btn xshop-btn--primary" style="inline-size:100%"><?php esc_html_e('Browse shop', 'xshop'); ?></a>
|
||
<?php else: ?>
|
||
<ul class="xshop-mini-cart__list">
|
||
<?php foreach ($items as $key => $item):
|
||
$product = $item['data'] ?? null;
|
||
if (!$product instanceof WC_Product) { continue; }
|
||
$name = $product->get_name();
|
||
$qty = (int) $item['quantity'];
|
||
?>
|
||
<li class="xshop-mini-cart__item">
|
||
<a href="<?php echo esc_url(get_permalink($product->get_id())); ?>">
|
||
<?php echo wp_get_attachment_image($product->get_image_id() ?: 0, 'thumbnail', false, ['alt' => esc_attr($name), 'loading' => 'lazy']); ?>
|
||
</a>
|
||
<span>
|
||
<a href="<?php echo esc_url(get_permalink($product->get_id())); ?>" style="color:var(--xshop-text);font-size:var(--xshop-text-sm)"><?php echo esc_html($name); ?></a>
|
||
<span style="display:block;color:var(--xshop-muted);font-size:var(--xshop-text-xs)"><?php echo esc_html(sprintf(esc_html__('%d × %s', 'xshop'), $qty, wp_strip_all_tags($product->get_price_html()))); ?></span>
|
||
</span>
|
||
<a href="<?php echo esc_url(wc_get_cart_remove_url($key)); ?>" aria-label="<?php esc_attr_e('Remove item', 'xshop'); ?>" style="color:var(--xshop-danger)">×</a>
|
||
</li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
<div style="border-block-start:1px solid var(--xshop-border);padding-block-start:var(--xshop-space-3);margin-block-start:var(--xshop-space-3);display:flex;justify-content:space-between;font-weight:var(--xshop-weight-bold)">
|
||
<span><?php esc_html_e('Subtotal', 'xshop'); ?></span>
|
||
<span><?php echo wp_kses_post($cart->get_cart_subtotal()); ?></span>
|
||
</div>
|
||
<div style="display:flex;gap:var(--xshop-space-2);margin-block-start:var(--xshop-space-3)">
|
||
<a href="<?php echo esc_url(wc_get_cart_url()); ?>" class="xshop-btn xshop-btn--secondary" style="flex:1"><?php esc_html_e('View cart', 'xshop'); ?></a>
|
||
<a href="<?php echo esc_url(wc_get_checkout_url()); ?>" class="xshop-btn xshop-btn--primary" style="flex:1"><?php esc_html_e('Checkout', 'xshop'); ?></a>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|