Snippet / Child theme functions.php or a snippets plugin

Include WooCommerce Products in Divi Search

A WordPress query snippet that lets the front-end search experience include WooCommerce products alongside posts and pages.

Use this when a Divi site has WooCommerce products that should appear in the standard WordPress search results. This is intentionally query-level and avoids depending on a specific Search module markup.

<?php
function dfy_include_products_in_site_search( $query ) {
    if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() ) {
        return;
    }

    $query->set( 'post_type', array( 'post', 'page', 'product' ) );
}
add_action( 'pre_get_posts', 'dfy_include_products_in_site_search' );

Notes

  • Test search result templates before using this on a live store.
  • If products use private catalogs, memberships, or hidden visibility rules, use a WooCommerce-aware search plugin instead.
  • Clear page and object cache after adding query-level changes.

Sources