admin管理员组文章数量:1435859
I am use Woocomerce with filter YITH WooCommerce Ajax Product Filter. I need create separate page OnSale. On page displayed only goods with discount and filter should apply this by default. I tried different solutions:
- Plugin - OnSale Page for WooCommerce
- Edit functions.php wiht Hook:
function action_woocommerce_product_query( $q ) { if ( is_admin() ) return; if ( isset( $_GET['onsale'] ) ) { if ( $_GET['onsale'] == 1 ) { $product_ids_on_sale = wc_get_product_ids_on_sale(); $q->set( 'post__in', $product_ids_on_sale ); } } } add_action( 'woocommerce_product_query', 'action_woocommerce_product_query', 10, 1 );
- I drew the page in Elementor with Wigdet DataSource - Sale... Work but slow
Main problem - when filtering, initial selection is reset and filter displays all products that match filter rule. I read and thought a lot. I realized that initial selection values need to be set in filter settings. I dug into plugin code and found hook - yith_wcan_query_vars_to_merge.
/**
* APPLY_FILTERS: yith_wcan_query_vars_to_merge
*
* Filters list of query vars to add to the query. - Фильтрует список переменных запроса, которые можно добавить в запрос.
*
* @param array $query_vars List of query vars
*
* @return array
*/
$query_vars = apply_filters( 'yith_wcan_query_vars_to_merge', $this->get_query_vars() );
Can someone please tell me how to use it correctly? Set constant selection...
function XXX( $this->get_query_vars ) {
$this->query_vars = array( ??? )
};
add_filter('yith_wcan_query_vars_to_merge', 'XXX');
What should be add to archive? In what format?
本文标签: wordpressChange initial selection filter query with hookStack Overflow
版权声明:本文标题:wordpress - Change initial selection filter query with hook - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745653425a2668565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论