• Resolved chadrex

    (@chadrex)


    Nub question but maybe there’s a simple workaround to not completely replace the existing search?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello @chadrex

    Hmm, I’m not entirely sure to what you’re referring to here. The Product’s SKU number?

    If so, then I can confirm that the feature is present in our product, but it is part of our Blocksy Pro package only with the WooCommerce Extra extension that it provides. It may be needed to upgrade your package in order to get this feature.

    Hope this helps!

    Thanks.

    Thread Starter chadrex

    (@chadrex)

    <font _mstmutation=”1″></font>Alas, I need not only the sku but also the product id which is set to the post after its creation.

    Hello @chadrex

    Could you please show me this ID you’re speaking of? Where do you set it, exactly? Or are you talking about the one that gets automatically assigned by WordPress/WooCommerce?

    Thread Starter chadrex

    (@chadrex)

    add_action( 'woocommerce_after_shop_loop_item', 'display_sku' );
    function display_sku() {
        global $product;
        if ( $product->get_id() ) {
            echo '<span class="sku"><bdi>ID: ' . $product->get_id() . '</bdi></span></div>';
        }
        }

    In short – I decided to use id to identify the product.

    Ok, I was able to verify this on my end and it seems that ID searching is not a WordPress/WooCommerce feature. The search function is strictly controlled by those (we only added SKU search as a bonus) and it would be required to get in touch with their developers directly for more information on how to change the behaviour.

    The behaviour is also present on the default themes – https://ibb.co/JdXb4Pv – which fully confirms that Blocksy is working as it should here and takes it out of the equation.

    Hope this clears things up!

    Thanks.

    Thread Starter chadrex

    (@chadrex)

    Continuing to research the question. There is a good example here, but there is a question of compatibility with live search

    add_filter( 'posts_search', 'product_search_by_id', 9999, 2 );
      
    function product_search_by_id( $search, $wp_query ) {
       global $wpdb;
       if ( is_admin() || ! is_search() || ! isset( $wp_query->query_vars['s'] ) || ( ! is_array( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] !== "product" ) || ( is_array( $wp_query->query_vars['post_type'] ) && ! in_array( "product", $wp_query->query_vars['post_type'] ) ) ) return $search;   
       $product_id = $wp_query->query_vars['s'];
       if ( ! get_post( $product_id ) ) return $search;
       $search = str_replace( 'AND (((', "AND (({$wpdb->posts}.ID IN (" . $product_id . ")) OR ((", $search );   
       return $search;   
    }
    • This reply was modified 1 year, 2 months ago by chadrex.

    Hello @chadrex

    I’m really, really sorry, but our policy does not provide support for implementing custom code, nor diagnosing it.

    Our live search also uses the built in WordPress API for searching, nothing special is going on. I think the recommendation here would be to get in touch with a knowledgeable developer, as they will be able to help you out carry these advanced modifications.

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to add [product id] support to search in header’ is closed to new replies.