wordpress 在shop页面上显示产品

复制代码
add_action('pre_get_posts', 'show_active_lotteries_only');

function show_active_lotteries_only($q)
{
// This will make sure that you're on the shop page
if (is_shop()) { $tax_query = array( array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => 'lottery' ) ); $q->set('tax_query', $tax_query); $q->set('post_type', 'product'); $q->set('post_status', 'publish'); $q->set('fields', 'ids'); $q->set('show_past_lottery', FALSE); } }
复制代码
add_action( 'pre_get_posts', 'show_active_lotteries_only' );
function show_active_lotteries_only( $q ){
$q->set( 'tax_query', array (
array(
'fields' => 'ids',
'post_type'=> 'product',
'show_past_lottery' => FALSE,
'tax_query' => array(array('taxonomy' => 'product_type' , 'field' => 'slug', 'terms' => 'lottery')),
)
));
}
--------------------------------------------------
add_action( 'woocommerce_product_query', 'product_hide_hcps' );
function product_hide_hcps($data){
// $hcps_datas = get_option('hcps_data');
$hcps_datas = ["category"=>'120', "options"=>"product"];
$tax_query = (array) $data->get( 'tax_query' );
// echo "<pre/>";var_dump($tax_query);die;
$select_values = $hcps_datas['category'];
$term_idArr = array( 120 );
$tax_query2[] = array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $term_idArr,//$select_values
'operator' => 'NOT IN'
);
$tax_query[] = array(
// 'taxonomy' => 'product_type',// wp_term_taxonomy表taxonomy字段值
// 'field' => 'term_id',// wp_terms表(term_id,name,slug)字段名
// 'terms' => ['15'],//wp_terms 字段名(term_id,name,slug)对应的值
// 'operator' => 'NOT IN'
);
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN', // or 'NOT IN' to exclude feature products
);
$tax_query[] = array(
'taxonomy' => 'product_type',
'field' => 'name',
'terms' => 'simple',//variable
'operator' => 'IN', // or 'NOT IN' to exclude feature products
);

if (!is_admin()) {
$data->set( 'tax_query', $tax_query );
}
}
posted @   也许明天  阅读(73)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
历史上的今天:
2015-08-04 1.5后台修改添加TDK
点击右上角即可分享
微信分享提示