Files
mccans-theme/actions/ShopPageShowCatsInsteadAction.php
2025-07-18 15:48:14 -07:00

47 lines
1.6 KiB
PHP

<?php
namespace Actions;
use ofc\RadAction;
class ShopPageShowCatsInsteadAction extends RadAction
{
/**
* @var string WordPress hook to attach to.
*/
protected string $hookName = 'woocommerce_before_main_content';
/**
* @var int Hook priority.
*/
protected int $priority = 10;
/**
* Your action callback.
*/
public function callback()
{
if (!is_shop()) {
return;
}
remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
remove_action('woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10);
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
remove_action('woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30);
remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination', 10);
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5);
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
$productCats = site()->getTerm('product_cat');
$withoutUncategorized = array_filter($productCats, fn ($c) => $c->slug != "uncategorized");
$topLevelCats = array_filter($withoutUncategorized, fn ($c) => $c->parent == 0);
foreach ($topLevelCats as $cat) {
echo site()->render("page-tile", $cat);
}
// var_dump($topLevelCats);
}
}