You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让WooCommerce产品每页数量筛选器在Elementor自定义页面生效

解决Elementor Products元素页面的WooCommerce钩子与分页设置问题

不用从头开发,Elementor针对WooCommerce产品小部件提供了专属的钩子和过滤器,直接用这些就能解决你的问题:

1. 让自定义钩子在Elementor产品页面生效

Elementor的Products小部件不会触发woocommerce_before_shop_loop这类原生商店页面钩子,你可以通过Elementor的小部件渲染钩子来触发自定义函数:

add_action('elementor/widget/before_render_content', function($widget) {
    // 判断当前渲染的是WooCommerce Products小部件
    if ($widget->get_name() === 'woocommerce-products') {
        custom_function(); // 执行你的自定义函数
    }
});

如果需要更精准的触发时机,也可以用Elementor为该小部件提供的专属钩子elementor/widget/woocommerce-products/before_render。

2. 同步主商店的“每页产品数量”设置

Elementor Products小部件默认读取自身的分页配置,要和主商店设置同步,用过滤器覆盖它的查询参数即可:

add_filter('elementor/widget/woocommerce-products/query_args', function($query_args, $widget) {
    // 获取WooCommerce后台设置的每页产品数
    $shop_per_page = get_option('posts_per_page');
    if ($shop_per_page) {
        $query_args['posts_per_page'] = $shop_per_page;
    }
    return $query_args;
}, 10, 2);

将上述代码添加到你的插件文件或主题的functions.php中即可生效。

内容的提问来源于stack exchange,提问作者legalpsyxo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 17:33:13