Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1490772

    Hallo Zusammen, bei Woocommerce kann man ja einstellen, wo ein Produkt gezeigt werden soll.
    Im Shop und den Suchergebnissen, Nur im Shop, nur Suchergebnisse oder ausgblendet.
    Leider funktioniert das nicht für die Enfold Suche und bei Ähnlichen Produkten wird es auch angezeigt, wenn man es zb auf ausgeblendet setzt. Ich habe es jetzt mit CSS gelöst, aber vielleicht könnte man das ja mit einem Update in Zukunft mal besser lösen?

    Danke und Gruß KiM

    #1490787

    Hey Blatze,

    Thank you for the inquiry.

    Try to add this code in the functions.php file to adjust the search query for products:

    function ava_pre_get_posts_mod( $query ) {
        if ( ! is_admin() && $query->is_search() && $query->is_main_query() ) {
            if ( class_exists( 'WooCommerce' ) && ( $query->get( 'post_type' ) === 'product' || isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' ) ) {
    
                $meta_query = (array) $query->get( 'meta_query' );
    
                $meta_query[] = array(
                    'key'     => 'catalog_visibility',
                    'value'   => array( 'hidden', 'exclude-from-search' ),
                    'compare' => 'NOT IN'
                );
    
                $query->set( 'meta_query', $meta_query );
            }
        }
    }
    add_action( 'pre_get_posts', 'ava_pre_get_posts_mod', 20 );
    

    Let us know the result.

    Best regards,
    Ismael

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.