46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Actions;
|
|
|
|
use ofc\RadAction;
|
|
|
|
class DontShowProductsOnShopLandingPageAction extends RadAction
|
|
{
|
|
/**
|
|
* @var string WordPress hook to attach to.
|
|
*/
|
|
protected string $hookName = 'parse_query';
|
|
|
|
/**
|
|
* @var int Hook priority.
|
|
*/
|
|
protected int $priority = 99;
|
|
|
|
/**
|
|
* Your action callback.
|
|
*/
|
|
public function callback()
|
|
{
|
|
if (!is_shop()) {
|
|
return;
|
|
}
|
|
|
|
// Remove everything hooked to the product loop
|
|
remove_all_actions('woocommerce_before_shop_loop');
|
|
remove_all_actions('woocommerce_shop_loop');
|
|
remove_all_actions('woocommerce_after_shop_loop');
|
|
|
|
// Also prevent product loop rendering itself
|
|
remove_all_actions('woocommerce_before_main_content');
|
|
remove_all_actions('woocommerce_after_main_content');
|
|
remove_all_actions('woocommerce_no_products_found');
|
|
|
|
add_action('pre_get_posts', function ($query) {
|
|
if (!is_admin() && $query->is_main_query()) {
|
|
$query->set('post_type', 'product');
|
|
$query->set('posts_per_page', 0);
|
|
}
|
|
}, 20);
|
|
}
|
|
}
|