Reading list Switch to dark mode

    How to Use Product Attributes Lookup Table for Catalog Filtering in WooCommerce?

    Updated 26 May 2023

    In this dev blog article, we will discuss how to use the WooCommerce product attribute lookup table for filtering catalog products. But before that, let us understand some basic things.

    What is the product attributes lookup table?

    WooCommerce migrated its own tables from 6.3 and introduced a table product attribute lookup table with the name “wc_product_attributes_lookup” which contains the following information and it is offering the ability to filter products by attribute accurately.

    • Product id
    • Product or parent id
    • Taxonomy
    • Term id
    • Variation attribute
    • Stock

    Why do we need this table?

    This problem arises when products have some variation products and some have stock and some of out of stock.

    What happened is that when the attribute is selected for filtering then all the variation products having the filtered attribute were displayed even though the attribute is out of stock.

    That’s why we need product attributes lookup table in WooCommerce to filter attributes accurately.

    Searching for an experienced
    Woocommerce Company ?
    Find out More

    New setting in the product tab

    After the first database migration is complete, a new “Advance” section will appear in the products tab settings of WooCommerce. The section will include options shown in the attached image file.

    product-filter-catalog

    How to enable the feature?

    1. First put this code somewhere in the file so that WooCommerce runs it at initialization time. It would be better to call the code snippet on the woocommerce_init hook.

    wc_get_container()->get( \Automattic\WooCommerce\Internal\ProductAttributesLookup\LookupDataStore::class )->show_feature();

    2. After successfully running the above code, go to the WooCommerce->Status–>Tools page. On this page, you will see a new tool with the title “Create and fill product attributes lookup table”.

    create-product-attribute-lookup-table

    3. Click on the “Create” button. This will create a product attribute lookup table and call(trigger) the scheduled task that will fill the table with valid information based on the products that exist in the database.

    The scheduler runs in a batch size of 10. You can modify the batch size also. While creating and filling the table the “Create” button will be disabled.

    Note – WooCommerce updates the product attributes lookup table even if “Enable table usage” is turned off. This happens when creating or updating a product.

    The table is automatically turned on once the initial database migration is complete.

    How to regenerate the product lookup table data?

    Once the initial database migration is completed then the “Regenerate the product attributes lookup table” will be available under the WooCommerce –> Status –> Tools.

    product-attribute-tool

    You can regenerate the product attributes lookup table data for the whole table at once or you can regenerate for the selected products only.

    When you regenerate the product attributes lookup table data for the whole table then it will empty the table and generate it recursively one by one.

    You can also select products to whom you want to regenerate the product attributes lookup table data.

    How to modify the batch size of (re)generating product attribute lookup table data?

    You can modify the batch size by adding the following code. By default the batch size is 10 products that will be processed in each run of the action scheduler.

    This value can be customized by using the “woocommerce_attribute_lookup_regeneration_step_size” filter.

    add_filter('woocommerce_attribute_lookup_regeneration_step_size', function( $batch_size ) {
        $batch_size: 50;
        return $batch_size;
    });

    Conclusion: Product attribute lookup table

    That’s all about the product attribute lookup table. Now you are able to create a product attribute lookup table and fill data in that table.

    Also, you are able to do a regeneration of the table and fill in the data. We have seen how can we modify the batch size of (re)generating the data in the scheduler that will run in each process.

    WooCommece Support

    Kindly visit the WooCommerce plugins page to see our add-ons. For any technical assistance, please raise a ticket or reach us by mail at [email protected]

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home