HUSKY - Product Filter for WooCommerce

Elementor 产品筛选:在 Elementor 中使用 HUSKY

HUSKY 支持用 Elementor 搭建的 WooCommerce 商店。在 Shortcode 小工具中放入 [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');

});

相关文章: 与 Elementor 的兼容性, 使页面构建器和自定义模板可过滤