50 lines
1.8 KiB
PHP
50 lines
1.8 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', ['url', 'thumbnail', 'title', 'count', 'parent']);
|
|
|
|
$withoutUncategorized = array_filter($productCats, fn ($c) => !str_contains($c["url"], "uncategorized"));
|
|
$topLevelCats = array_filter($withoutUncategorized, fn ($c) => $c["parent"] == 0);
|
|
|
|
echo "<div class='row'>";
|
|
foreach ($topLevelCats as $cat) {
|
|
echo "<div class='col-12 col-sm-6 col-md-4 col-lg-3 mb-4'>".site()->render("page-tile", $cat)."</div>";
|
|
}
|
|
echo "</div>";
|
|
// var_dump($topLevelCats);
|
|
}
|
|
}
|