woocommerce-multilingual
/
compatibility
/
WcAjaxLayeredNav
/
class-wcml-ajax-layered-nav-widget.php
class-wcml-ajax-layered-nav-widget.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | class WCML_Ajax_Layered_Nav_Widget implements \IWPML_Action { |
| 5 | |
| 6 | public function add_hooks() { |
| 7 | add_filter( 'wc_ajax_layered_nav_sizeselector_term_id', [ $this, 'wc_ajax_layered_nav_sizeselector_term_id' ] ); |
| 8 | add_filter( 'wc_ajax_layered_nav_query_editor', [ $this, 'wc_ajax_layered_nav_query_editor' ], 10, 3 ); |
| 9 | } |
| 10 | |
| 11 | public function wc_ajax_layered_nav_sizeselector_term_id( $term_id ) { |
| 12 | $ulanguage_code = apply_filters( 'wpml_default_language', null ); |
| 13 | $term_id = apply_filters( 'wpml_object_id', $term_id, 'category', true, $ulanguage_code ); |
| 14 | return $term_id; |
| 15 | } |
| 16 | |
| 17 | public function wc_ajax_layered_nav_query_editor( $posts, $attribute, $value ) { |
| 18 | $posts = get_posts( |
| 19 | [ |
| 20 | 'post_type' => 'product', |
| 21 | 'numberposts' => -1, |
| 22 | 'post_status' => 'publish', |
| 23 | 'fields' => 'ids', |
| 24 | 'no_found_rows' => true, |
| 25 | 'tax_query' => [ |
| 26 | [ |
| 27 | 'taxonomy' => $attribute, |
| 28 | 'terms' => $value, |
| 29 | 'field' => 'term_id', |
| 30 | ], |
| 31 | ], |
| 32 | ] |
| 33 | ); |
| 34 | return $posts; |
| 35 | } |
| 36 | } |
| 37 |