如何将 Woocommerce 搜索结果 orderby 更改为价格从低到高 [英] How to change the Woocommerce search result orderby into price low to high
问题描述
在我的网站上,我将 woocommerce 更新为 3.3.3,然后默认情况下显示产品搜索结果的搜索结果页面以相关性"顺序开始.但是 woocommerce 有错误,我报告了
请使用下面的钩子:
add_action('woocommerce_product_query', 'jwc_custom_product_query');函数 jwc_custom_product_query( $query ) {if(!$query->is_main_query())返回;if(!isset($query->query['s']))返回;$query->set('order', 'ASC');$query->set('orderby', 'price');返回 $query;}
On my website i updated the woocommerce into 3.3.3 then the search result page showing products search results start with the "relevance" orderby by default. But woocommerce have bug i reported that bug and they solved by editing one core file. The Bug is relevance is not showing on the search page containing dropdown not showing "relevance" orderby by default.
Now i want to change the default "relevance" orderby into price low to high i added this code in function.php.
add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
function am_woocommerce_catalog_orderby( $args ) {
if ('is_search' ) {
$args['meta_key'] = '_price';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'asc';
return $args;
}
}
This code is working for me but the search page containing dropdown field value still showing relevance i want to change that one also into price low to high.Please see attached screenshot. How i do that ?? could you please someone help me!!
Please use the below hook:
add_action( 'woocommerce_product_query', 'jwc_custom_product_query' );
function jwc_custom_product_query( $query ) {
if( ! $query->is_main_query() )
return;
if( ! isset( $query->query['s'] ) )
return;
$query->set( 'order', 'ASC' );
$query->set( 'orderby', 'price' );
return $query;
}
这篇关于如何将 Woocommerce 搜索结果 orderby 更改为价格从低到高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!