• Resolved abhinavebizon

    (@abhinavebizon)


    Hi Support,

    We’re looking for the best way to trigger an Algolia reindex automatically when an order is placed on WooCommerce. Currently, we have to manually use the Re-index button (as shown in the attached screenshot), but with large order volumes, this isn’t feasible.

    Our plan is to create a cron job in WordPress to reindex and sync stock levels and other product metadata at a specified interval. Could you advise on the best approach to ensure updates are properly indexed?

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

    (@tw2113)

    The BenchPresser

    Hi @abhinavebizon

    I know we have that type of “order completed” watching in our WP Search with Algolia Pro premium addon, but also unsure about budgets for you. In it we listen to the woocommerce_order_status_completed WooCommerce hook and re-index each product from the order.

    A bit similar to the snippet at https://github.com/WebDevStudios/algolia-snippet-library/blob/main/indexing/reindex-on-comment-save.md where we’re showing how to sync a post after it receives a comment.

    Regarding your ideas, that’s definitely a valid alternative approach, and making use of WP-CLI from the free plugin would be a great way to achieve.

    Thread Starter abhinavebizon

    (@abhinavebizon)

    Hello, thanks for your response.

    To clarify, we have a third-party integration that updates our WooCommerce product inventory from Salesforce. Since these updates occur frequently, we are experiencing issues where product stock statuses are not syncing correctly with Algolia. For example, some products that are back in stock remain marked as out of stock in Algolia, and vice versa.

    Could you provide some hooks or actions that we can use in our cron job to reindex the data every hour?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I would recommend checking out https://github.com/WebDevStudios/wp-search-with-algolia/wiki/WP-CLI if you’re wanting something that can be done via a cron job on the host server.

    Thread Starter abhinavebizon

    (@abhinavebizon)

    No, the CLI will not assist us in meeting our requirements. Could you suggest any action (do_action) that would help us achieve this?

    I tried using the do_action below, but it didn’t work as expected:
    do_action( ‘algolia_posts_index_post_product_updated’, $product, $records );

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You can see how we wire things up for individual post watching and callbacks used at https://github.com/WebDevStudios/wp-search-with-algolia/blob/main/includes/watchers/class-algolia-post-changes-watcher.php We essentially pass a given post through an available method to sync an individual item.

    The WP-CLI methods can be found at https://github.com/WebDevStudios/wp-search-with-algolia/blob/main/includes/class-algolia-cli.php and they’re also executed via PHP, and could be a starting point for wiring things up too in a way that works better for you.

    Admittedly curious why WP-CLI wouldn’t work, but if it’s a case of not having access to the server that way and/or ability to schedule cron jobs, then I do get that much.

    Thread Starter abhinavebizon

    (@abhinavebizon)

    Hello,

    Thanks for sharing the CLI documentation.

    After gaining server access, I connected via SSH and ran the following command:

    wp algolia re-index --all --quiet

    The command executed successfully, but the product data (such as stock and price) is not syncing on the Algolia dashboard.

    However, when I manually reindex from WP-Admin > Algolia Search > Autocomplete > Products (as shown in the screenshot), the updates reflect correctly.

    Could you please guide me on what needs to be done to ensure the CLI reindexing updates the product data properly?

    Thanks!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    As long as the indexing of those shared attributes are wired up properly, with the appropriate filters and the like, the re-index method shouldn’t matter and all the intended data should be getting pushed into the index.

    Since you mention stock/price data, is this your own rolling of I assume WooCommerce, or are you also making use of our Pro addon as well?

    Alternatively, does it work when you re-index the specific index? For example `wp algolia re-index posts_products to target just that one index.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any news or changes here @abhinavebizon ?

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

The topic ‘Algolia automatic reindex’ is closed to new replies.