33 lines
1.0 KiB
PHP
33 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* Product Grid — wraps product cards in CSS grid.
|
|
*
|
|
* Args: ['products' => WC_Product[]|int[], 'columns'=>int, 'empty_text'=>string]
|
|
*
|
|
* @package XShop
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$products = $args['products'] ?? [];
|
|
$columns = isset($args['columns']) ? max(1, min(6, (int) $args['columns'])) : 4;
|
|
|
|
if (empty($products)) {
|
|
$text = $args['empty_text'] ?? esc_html__('No products found.', 'xshop');
|
|
get_template_part('template-parts/components/empty-state', null, ['title' => esc_html__('No products', 'xshop'), 'text' => $text]);
|
|
return;
|
|
}
|
|
?>
|
|
<ul class="xshop-products" data-columns="<?php echo esc_attr((string) $columns); ?>">
|
|
<?php foreach ($products as $p):
|
|
$product = is_int($p) ? wc_get_product($p) : $p;
|
|
if (!$product instanceof WC_Product) { continue; }
|
|
?>
|
|
<li class="xshop-products__item">
|
|
<?php get_template_part('template-parts/components/product-card', null, ['product' => $product, 'show_hooks' => $args['show_hooks'] ?? false]); ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|