woocommerce - woocommerce_product_query 钩子与 Elementor 产品选项卡
问题描述
下面的钩子
function custom_pre_get_posts_query( $q ) {
$tempAddress = $_COOKIE["tempAddress"];
$categories_to_exclude = array();
if (strpos($tempAddress, 'New York') !== FALSE)
{
//categories_to_exclude;
//$q->set();
}
else
{
$args = apply_filters('woocommerce_related_products_args',
array(
'post_type' => 'product',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
),
),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id', // Or 'name' or 'term_id'
'terms' => array(51,52,53),
'operator' => 'NOT IN', // Excluded
)
)
)
);
$q->set( 'tax_query', $args );
}}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
帮助我们删除 WooCommerce 中某些类别的产品。但是,当主题在某个页面(例如主页)上有 Elementor 产品选项卡时,不会应用挂钩。
任何想法?
非常感谢!
解决方案
推荐阅读
- pine-script - 函数“max_bars_back”未按预期工作
- sqlite - 为什么我会得到“不明确的列名:account.accrued”?
- python - 将列表元素拆分为python中的列表
- c# - Unity UI - 如何制作“复合”布局组以在同一位置组合多个图像?
- r - 如何在没有“c”的圆括号中将矢量放入胶水中?
- sqlite - 无法在 sqlite 中使用 UUID id 保存聚合根
- arrays - 将 Numpy 数组加倍成更大的数组
- rxjs - 在 rxjs 中调用完成后我应该取消订阅吗?
- python - python - 如何使用python中的opencv找出一个图像中存在的一条线是否是不同图像中存在的另一条线的子集?
- gdb - gdb 突然开始忽略断点