Elementor产品筛选:在Elementor中使用HUSKY
HUSKY 可与基于 Elementor 构建的 WooCommerce 商店配合使用。通过短代码小部件中的 [woof] 短代码将筛选器添加到任何页面,或将其作为常规小部件保留在侧边栏中。
如果产品网格由 Elementor 自身渲染(自定义循环或产品模板),请使用以下代码在子主题 functions.php 中将其连接到筛选器:
add_action('pre_get_posts', function ($query) {
if (defined('ELEMENTOR_VERSION')) {
if (is_object($query) AND isset($query->query['post_type'])) {
if ($query->query['post_type'] === 'product' /* AND is_page(__YOUR_PAGE_ID__)*/) {
global $WOOF;
if (is_object($WOOF) AND !empty(woof()->get_request_data())) {
woof()->woof_products_ids_prediction(true);
$query->query_vars['post__in'] = $_REQUEST['woof_wp_query_ids'];
}
}
}
}
return $query;
});
取消注释 is_page(__YOUR_PAGE_ID__) 以仅在特定页面上运行筛选。
如果在 HUSKY 激活时 Elementor 编辑器停止打开,请从 Elementor 注销 HUSKY 小部件:
add_action('elementor/widgets/widgets_registered', function($widgets_manager)
{
$widgets_manager->unregister_widget_type('wp-widget-woof_widget');
});