Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created January 11, 2016 16:08
Show Gist options
  • Save mgibbs189/c46e43f5d9c1caeebdc6 to your computer and use it in GitHub Desktop.
Save mgibbs189/c46e43f5d9c1caeebdc6 to your computer and use it in GitHub Desktop.
FacetWP - add a WooCommerce "On Sale" facet
<?php
// Create a facet named "on_sale" with the Data Source of "Post Type"
// Add this to functions.php
function fwp_is_sale( $params, $class ) {
if ( 'is_sale' == $params['facet_name'] ) {
$post_id = (int) $params['post_id'];
$variable_sale_price = get_post_meta( $post_id, '_min_variation_sale_price', true );
$sale_price = get_post_meta( $post_id, '_sale_price', true );
if ( ! empty( $variable_sale_price ) || ! empty( $sale_price ) ) {
$params['facet_value'] = 1;
$params['facet_display_value'] = 'On sale';
return $params;
}
// If not on sale, skip the facet for this post
return false;
}
// Proceed normally
return $params;
}
add_filter( 'facetwp_index_row', 'fwp_is_sale', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment