Files
wordpress-theme-aksrt/templates/parts/shop/product-card.php
T
kate522 433b7cb3a6 feat(shop): category filter bar + sort/load-more 1:1 UX
Port zibll hierarchical cat tabs, multi-metric sort with price toggle,
skeleton/empty states, and REST archive payload (header/html/paginate)
while reusing product-card template for AJAX HTML.
2026-07-18 16:42:52 +08:00

60 lines
2.3 KiB
PHP

<?php
/**
* Shared product card (archive / related / storefront).
*
* Expected args:
* - product: array from \AKSRT\Shop\Shop::build_product_card_view()
* - show_sales: bool (optional)
* - sales_cfg: array (optional; used when show_sales not provided)
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
$product = is_array($args['product'] ?? null) ? $args['product'] : [];
if (empty($product) || empty($product['id'])) {
return;
}
$sales = (int) ($product['sales'] ?? 0);
if (array_key_exists('show_sales', $args)) {
$show_sales = !empty($args['show_sales']);
} else {
$sales_cfg = is_array($args['sales_cfg'] ?? null) ? $args['sales_cfg'] : [];
$mode = (string) ($sales_cfg['show'] ?? 'show');
$min_sales = max(0, (int) ($sales_cfg['show_min'] ?? 0));
$show_sales = ($mode === 'show' && $sales > 0) || ($mode === 'threshold' && $sales >= $min_sales);
}
$title = (string) ($product['title'] ?? '');
$permalink = (string) ($product['permalink'] ?? '#');
$image = (string) ($product['image'] ?? '');
$excerpt = (string) ($product['excerpt'] ?? '');
$price = (float) ($product['price'] ?? 0);
?>
<article class="aksrt-product-card product-item posts-item card ajax-item">
<a href="<?php echo esc_url($permalink !== '' ? $permalink : '#'); ?>" class="aksrt-product-card__link">
<?php if ($image !== '') : ?>
<div class="aksrt-product-card__image">
<img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr($title); ?>" loading="lazy">
</div>
<?php else : ?>
<div class="aksrt-product-card__image aksrt-product-card__image--placeholder"><i class="fas fa-image" aria-hidden="true"></i></div>
<?php endif; ?>
<div class="aksrt-product-card__body">
<h3 class="aksrt-product-card__title"><?php echo esc_html($title); ?></h3>
<?php if ($excerpt !== '') : ?>
<p class="aksrt-product-card__excerpt"><?php echo esc_html(wp_trim_words($excerpt, 15)); ?></p>
<?php endif; ?>
<div class="aksrt-product-card__footer">
<span class="aksrt-product-card__price">¥<?php echo esc_html(number_format($price, 2)); ?></span>
<?php if ($show_sales) : ?>
<span class="aksrt-product-card__sales"><?php printf(esc_html__('已售 %d', 'aksrt'), $sales); ?></span>
<?php endif; ?>
</div>
</div>
</a>
</article>