<?php
// Add the new data source
add_filter( 'facetwp_facet_sources', function( $sources ) {
$sources['woocommerce']['choices']['woo/price_incl_tax'] = __( 'Price (incl. tax)' );
return $sources;
}, 20 );
// Handle the new data source
add_filter( 'facetwp_indexer_post_facet', function( $return, $params ) {
$facet = $params['facet'];
$defaults = $params['defaults'];
$post_id = (int) $defaults['post_id'];
if ( 'product' == get_post_type( $post_id ) && 'woo/price_incl_tax' == $defaults['facet_source'] ) {
$product = wc_get_product( $post_id );
$price = wc_get_price_including_tax( $product );
$defaults['facet_value'] = $price;
$defaults['facet_display_value'] = $price;
FWP()->indexer->index_row( $defaults );
return true;
}
return $return;
}, 10, 2 );