I want to create a custom search for a woocommerce product with woocommerce fields and advanced custom fields.
Like price range of woocommerce fields and other fields type using advance custom fields (ACF).
- 1 like
- 1 comment
Dhananjay Kumar |26 Jul at 11:07
I want to create a custom search for a woocommerce product with woocommerce fields and advanced custom fields.
Like price range of woocommerce fields and other fields type using advance custom fields (ACF).
Dhananjay Kumar26 Jul at 12:07
I got the solution, with below script:
We have work on product-arcive.php
------------------------------------------------------------------------------------------------------
$args['post_type'] = 'product';
$taxquery=array();
if(count($_REQUEST)>0){
foreach($_REQUEST as $key=>$val){
if($key=="min_price" && $val!=""){
$passarg[]=array('key'=> '_price',
'value' => $val,
'compare' => '>=',
'type' => 'NUMERIC'
);
}
if($key=="max_price" && $val!=""){
$passarg[]=array('key'=> '_price',
'value' => $val,
'compare' => '<=',
'type' => 'NUMERIC'
);
}
if($key=="acf_field"){
$passarg[]=array('key'=> $key,
'value' => $val,
'compare' => '=',
);
}
}
}
$args['meta_query'] = $passarg;
query_posts( $args );
$the_query = new WP_Query( $args );
------------------------------------------------------------------------------------------------------