Created
April 25, 2018 21:24
-
-
Save djrmom/c53839ed3a8a40dddf1d7a93e4348533 to your computer and use it in GitHub Desktop.
facetwp re-add woocommerce post clauses for sort by price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * re-add post-clause for woocommerce after facetwp updates the query vars | |
| */ | |
| add_action( 'pre_get_posts', function( $query ) { | |
| if ( 'product_query' == $query->get('wc_query') && true == $query->get('facetwp' ) && 'price' == $query->get('orderby') ) { | |
| if ( 'DESC' == $query->get('order') ) { | |
| add_filter( 'posts_clauses', array( wc()->query, 'order_by_price_desc_post_clauses' ) ); | |
| } else { | |
| add_filter( 'posts_clauses', array( wc()->query, 'order_by_price_asc_post_clauses' ) ); | |
| } | |
| } | |
| }, 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment