Gists

4 weeks ago
<?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' == $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 );
9 months ago
<?php

add_filter( 'facetwp_facet_sources', function( $sources ) {
    foreach ( $sources['custom_fields']['choices'] as $key => $value ) {
        if ( 0 === strpos( $value, '_stcr' ) ) {
            unset( $sources['custom_fields']['choices'][ $key ] );
        }
    }
    return $sources;
});
4 years ago
<?php
/** inherit adds attachment indexing **/
add_filter( 'facetwp_indexer_query_args', function( $args ) {
    $args['post_status'] = array( 'publish', 'inherit' );
    return $args;
});

/** post_mime_type is the column in the posts table to add **/
add_filter( 'facetwp_facet_sources', function( $sources ) {
    $sources['posts']['choices']['post_mime_type'] = 'Media Type';
    return $sources;
});

/** modifies string for mine type
 ** example image/png becomes image
 **/
add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'post_mime_type' == $params['facet_source'] ) {
		  $value = $params['facet_display_value'];
		  $value = substr( $value, 0, strpos( $value, '/' ) );
		  $params['facet_value'] = $params['facet_display_value'] = $value;
    }
    return $params;
}, 10, 2 );