Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi @felipee94

    The example at https://webdevstudios.com/2021/02/09/wp-search-with-algolia/#indexing-custom-fields would fit really well for you.

    Only differences are going to be that instead of fetching post meta via Advanced Custom Fields in your callback, you’d be fetching EDD product information. I’d recommend using EDD functionality to check if a passed in post is an EDD product and return early if not. That way you’re only customizing for EDD with the used callback.

    Thread Starter felipee94

    (@felipee94)

    That worked, thanks. I can already see the indexed data in Algolia, but not in instantsearch page yet. I’m trying to create a rangeSlider for prices with this code but the data doesn’t appear:

    instantsearch.widgets.rangeSlider({
    container: ‘#facet-price’,
    attribute: ‘edd_price’,
    }),

    Does “12.00” in Algolia mean to be a string? this way the prices are listed.
    Is the update of data from Algolia to the plugin automatically?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Going to depend on how you stored the attribute.

    If you stored the price as such $attributes[ 'edd_price ] = $price; then that would be how it’s stored in Algolia.

    Yes the quotes should be indicating string.

    I believe the algolia_searchable_post_shared_attributes part should be helping with instantsearch, but the attribute may need to be marked as facetable or filterable in Algolia either via their dashboard settings or via code.

    I believe that can be found at https://github.com/WebDevStudios/wp-search-with-algolia/wiki/Index-Settings but may need to poke around the wiki a bit more yet.

    Thread Starter felipee94

    (@felipee94)

    The problem was the string format, changing it to number worked. However, if I don’t set a fixed minimum value, the range slider doesn’t work. Also the slider values ​​aren’t updated when selecting a category, but when changed the slider, the categories are updated.

    I would like to bring only specific categories (in this case subcategories of ‘download_category’). Do you know how I can do it? Grateful

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    May need to set a minimum price, even if it’s perhaps a float 0.00 value.

    The widgets changing in conjunction together is likely going to be more on the Algolia side than anything specific to the plugin, however I’m also curious what sort of settings may be available for the widgets. Been a hot minute since I last really looked at them.

    Which widget type are you using for the subcategories at the moment? If you’re not sure, then if you have a public link I could see things at would help as well.

    Thread Starter felipee94

    (@felipee94)

    I’m testing on localhost but I attached two images. The idea is to create a product filters page and to specify the download categories (Graphics, Templates, Fonts…) and the page already loaded with their products.

    https://ibb.co/vxG24zJ
    https://ibb.co/dfyYtD5

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I know in the past I used the Configure widget to set some initial categories.

    https://www.algolia.com/doc/api-reference/widgets/configure/js/

    May or may not fit your needs here. This was done with WooCommerce, but I suspect it’d transform just fine for EDD

    JS/Algolia widget usage

    let data = JSON.parse(woo_queried_terms);
    let item_parts = []
    for ( const item of data.terms ) {
    	item_parts.push( 'taxonomies.product_cat:"' + item + '"' );
    }
    let the_query = item_parts.join(' AND ');
    search.addWidgets([
    	instantsearch.widgets.configure({
    		filters: the_query,
    	}),
    ]);
    

    Inline JS constnat creation on the server.

    global $wp_query;
    
    $term_parts = explode( '/', $wp_query->query['product_cat'] );
    $results['total'] = count( $term_parts );
    $results['terms'] = [];
    foreach( $term_parts as $part ) {
    	$term = get_term_by( 'slug', $part, 'product_cat' );
    	$results['terms'][] = $term->name;
    }
    wp_add_inline_script( 'algolia-handle', 'const woo_queried_terms = \'' . json_encode( $results ) . '\'; ' );
    
    Thread Starter felipee94

    (@felipee94)

    I wanted filtering just on frontend side. After some searching I did it with transformItens filters on refinamentList. I don’t know if it is the best way, but worked for me. I’ll paste below the code for maybe help someone trying to do the same.

    const cats = [‘cat1′,’cat2′,’cat3′,’cat4’];

    instantsearch.widgets.refinementList)({

    transformItems(items) {
    return items.filter(item => cats.includes(item.label));
    },
    }),

    • This reply was modified 3 years, 9 months ago by felipee94.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like a valid way to me, to be honest, and whatever gets the job done.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Easy Digital Downloads custom fields’ is closed to new replies.