Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created April 25, 2018 21:24
Show Gist options
  • Select an option

  • Save djrmom/c53839ed3a8a40dddf1d7a93e4348533 to your computer and use it in GitHub Desktop.

Select an option

Save djrmom/c53839ed3a8a40dddf1d7a93e4348533 to your computer and use it in GitHub Desktop.
facetwp re-add woocommerce post clauses for sort by price
<?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