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?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745653426a4638400.html
评论列表(0条)