WebDevStudios / wp-search-with-algolia

Improve search on your site. Autocomplete is included, along with full control over look, feel and relevance.
https://wordpress.org/plugins/wp-search-with-algolia/
138 stars 54 forks source link

Woocommerce Variable Products Sale Price is not sent correctly to algolia. #387

Closed NowhereWM closed 8 months ago

NowhereWM commented 8 months ago

Describe the bug We are having a bug when the user is using the autocomplete and instant search by algolia. We are using wp-search-with-algolia free & pro version for a Woocommerce site. The issue is that when a woocommerce product is variable it sends the same price for regular price and sale price. Algolia's index has two different fields for regular price and sale price but the plugin sends the same value (regular price) for both fields.

To Reproduce You can search using the searchbar on the header for product "Senegal 4" at https://auto-motive.gr

Screenshots https://prnt.sc/hT7hdCl4Fpsz https://prnt.sc/A5kRf3jlGxdp

tw2113 commented 8 months ago

Based on what I'm seeing coming in for Algolia POST responses that are used to populate the suggestions, the sale price is still being listed as 155.00€. so if it should be a sale price of 128.00€, then something with the index hasn't been updated to reflect yet. Can you try updating the product one more time, without editing anything? Asking because I know we have this issue presently open:

https://github.com/WebDevStudios/wp-search-with-algolia/issues/384

The TLDR is that we re-index before term/meta data has been saved, and the idea with that issue would be to re-index at a slightly later point when that information HAS been saved.

NowhereWM commented 8 months ago

You are right, we just updated the product without any edit and it shows the sale price correct now. Any idea where this issue is coming from and how we can prevent it?

tw2113 commented 8 months ago

A workaround regarding just meta can be seen in the linked issue #384:

Right now, the workaround would be to add each meta key you want to get sync'd the first time, to the algolia_watch_post_meta_keys filter, of which the callback does it's own post sync, which runs on these actions: added_post_meta, updated_post_meta, deleted_post_meta

function wpswa_support_meta_data_watchers( $keys, $object_id ) {
    $keys[] = '_some_woocommerce_key';

    return $keys;
}
add_filter( 'algolia_watch_post_meta_keys', 'wpswa_support_meta_data_watchers', 10, 2 );

you'd need to determine the proper meta key that WooCommerce stores the value in.

That said, I do feel that we should make a decision on #384 more sooner than later since a lot of WooCommerce updates are very likely meta key based updates only, and the need to double save is going to affect meta only based updates across the board, regardless of Woo usage. Everyone would benefit.

Closing as not a broken functionality issue, but feel free to continue discussion as needed.