• I’m running Relevanssi on a Flatsome themed site and also using the Product GTIN (EAN, UPC, ISBN) for WooCommerce plugin and I’m having an issue with variable products for some reason.

    Flatsome’s AJAX search will pull parent products based off of UPC codes but it won’t pull children/variations for some reason. I tried running an admin search on a variable UPC and it pulls it up there so I’m not exactly sure what the disconnect is. I’m running the following snippet for Relevanssi to pull SKUs for variable products so I’d imagine it just needs something similar for UPCs, are you able to offer any insight on this please?

    // RELEVANSSI VARIABLE SKU SEARCH
    add_filter('relevanssi_content_to_index', 'rlv_index_variation_skus', 10, 2);
    function rlv_index_variation_skus($content, $post) {
        if ($post->post_type == "product") {
            $args = array('post_parent' => $post->ID, 'post_type' => 'product_variation', 'posts_per_page' => -1);
            $variations = get_posts($args);
            if (!empty($variations)) {
                foreach ($variations as $variation) {
                    $sku = get_post_meta($variation->ID, '_sku', true);
                    $content .= " $sku";
                }
            }
        }
     
        return $content;
    }

    Also another issue that I’m having is that Flatsome’s AJAX search will pull SKUs correctly but if I just hit enter instead of letting the AJAX results load then it takes me to the shop page and says no products found. I’m running Search & Filter Pro for my shop page if that gives you any insight.

    Any info you’re able to provide on either of these issues would be incredibly appreciated, thank you for your time.

Viewing 15 replies - 16 through 30 (of 31 total)
  • Thread Starter lateralus821

    (@lateralus821)

    I disabled the SKU search in the Flatsome settings and that fixed the issue, now the AJAX search works perfectly for both simple and variable product SKUs and UPCs.

    One other thing that seems a bit odd though is that if I search a SKU and hit enter before the AJAX search loads it will take me to the correct product page but if I search a UPC and hit enter before the AJAX search loads it just takes me to the shop page and shows all products – is there any way to get it to function like SKUs and bring me to the correct product page for the UPC?

    Plugin Author Mikko Saari

    (@msaari)

    That’s a WooCommerce feature that automatically redirects you to the product page if there’s exactly one search result. If the search returns multiple results, that does not happen. What do your UPCs look like?

    Thread Starter lateralus821

    (@lateralus821)

    The UPCs are unique so that they only hit one specific product, for example 850002123159.

    Plugin Author Mikko Saari

    (@msaari)

    In that case the WooCommerce single-result redirect should work with them. You say “shows all products” – the search result set is just single product, right?

    Perhaps your site is using a different mechanism that is somehow only working with SKUs. This should work:

    add_action('template_redirect', 'one_match_redirect');
    function one_match_redirect() {
        if (is_search()) {
            global $wp_query;
            if ($wp_query->post_count == 1) {
                wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
            }
        }
    }
    Thread Starter lateralus821

    (@lateralus821)

    I just tried that but it still functions the same.

    If I search for “850002123265” the AJAX search will bring up just that product in the search bar which is correct but if I hit enter it takes me to the shop page with all of the products visible and adds this to the url “/?product_cat=&s=850002123265&post_type=product”.

    Plugin Author Mikko Saari

    (@msaari)

    What do you mean with “all of the products visible”? Does the search return all posts? What results do you get if you search for this keyword in the Relevanssi admin search? Does that get you the exact results?

    Thread Starter lateralus821

    (@lateralus821)

    By all of the products visible I mean that it takes me to the shop page and it looks the same as if I went to /shop/.

    The admin search pulls the product correctly and so does the front end AJAX search if I let it load.

    Plugin Author Mikko Saari

    (@msaari)

    Ah, I see. So it does not take you to the search results page at all? That sounds like a problem with the search form, or perhaps the redirect throws you to the wrong place. It’s very hard to say anything more without seeing your site.

    What does this print out when you do the search?

    add_action('template_redirect', 'one_match_redirect');
    function one_match_redirect() {
        if (is_search()) {
            global $wp_query;
            if ($wp_query->post_count == 1) {
    var_dump($wp_query->posts['0']);
    exit();
                wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
            }
        }
    }
    Thread Starter lateralus821

    (@lateralus821)

    That actually crashed my site for some reason, after throwing it into my functions file and refreshing the site I just got the “site is experiencing technical difficulties” error.

    Plugin Author Mikko Saari

    (@msaari)

    Maybe a copy-paste problem? I tried the code on my test site and it works fine, no crashing. If there’s 0 or more than 1 result, everything’s normal, but with exactly 1 result it doesn’t do the redirect, but instead prints out the post object it would redirect to. What about this:

    add_action('template_redirect', 'one_match_redirect');
    function one_match_redirect() {
        if (is_search()) {
            global $wp_query;
            if ($wp_query->post_count == 1) {
    var_dump($wp_query);
    exit();
                wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
            }
        }
    }
    Thread Starter lateralus821

    (@lateralus821)

    Yeah that was an error on my end, sorry about that. I put in the snippet and it’s still having the same result. If I search for “850002123265” it just takes me to the shop page with every product loaded like normal and adds “/?product_cat=&s=850002123265&post_type=product” to the URL. Doing an admin search for that UPC only pulls the 1 correct result, I’m not sure what the disconnect is.

    Plugin Author Mikko Saari

    (@msaari)

    That does look like a regular search page URL, strange that it’s not displaying the search results page.

    Without seeing your site, it’s very hard to say what’s up with that, but I’d look at the templates to see what’s happening there.

    Does this trigger anything?

    add_action('template_redirect', 'one_match_redirect');
    function one_match_redirect() {
        if (is_search()) {
            global $wp_query;
    var_dump($wp_query);
    exit();
            if ($wp_query->post_count == 1) {
                wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
            }
        }
    }
    Thread Starter lateralus821

    (@lateralus821)

    If I buy a license for Relevanssi Premium would you be able to check out the site and troubleshoot it directly?

    That just pulled up a full page of code that looks like below and then a bunch of raw code from the products that show up on the store page from a search.

    object(WP_Query)#2005 (52) { ["query"]=> array(3) { ["post_type"]=> string(7) "product" ["product_cat"]=> string(0) "" ["post__in"]=> array(0) { } } ["query_vars"]=> array(75) { ["post_type"]=> string(7) "product" ["product_cat"]=> string(0) "" ["error"]=> string(0) "" ["m"]=> string(0) "" ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" ["subpost_id"]=> string(0) "" ["attachment"]=> string(0) "" ["attachment_id"]=> int(0) ["name"]=> string(0) "" ["static"]=> string(0) "" ["pagename"]=> string(0) "" ["page_id"]=> int(0) ["second"]=> string(0) "" ["minute"]=> string(0) "" ["hour"]=> string(0) "" ["day"]=> int(0) ["monthnum"]=> int(0) ["year"]=> int(0) ["w"]=> int(0) ["category_name"]=> string(0) "" ["tag"]=> string(0) "" ["cat"]=> string(0) "" ["tag_id"]=> string(0) "" ["author"]=> string(0) "" ["author_name"]=> string(0) "" ["feed"]=> string(0) "" ["tb"]=> string(0) "" ["paged"]=> string(0) "" ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["preview"]=> string(0) "" ["sentence"]=> string(0) "" ["title"]=> string(0) "" ["fields"]=> string(0) "" ["menu_order"]=> string(0) "" ["embed"]=> string(0) "" ["category__in"]=> array(0) { } ["category__not_in"]=> array(0) { } ["category__and"]=> array(0) { } ["post__in"]=> array(270) { [0]=> int(468) [1]=> int(470) [2]=> int(472) [3]=> int(474) [4]=> int(479) [5]=> int(481) [11]=> int(490) [19]=> int(501) [20]=> int(508) [23]=>

    Plugin Author Mikko Saari

    (@msaari)

    Yes, I could do that.

    Based on the WP_Query output, the search terms are missing. That’s why it’s showing you all products: there’s no search term to restrict it. Where does the search term go? Can it be because it’s just numbers? If you throw in a letter after the number, does that get you a “nothing found” page?

    Thread Starter lateralus821

    (@lateralus821)

    Yes if I put a letter after the UPC and hit search then it pulls up the shop page with the “No products were found matching your selection.” text.

    I’ll find out tomorrow if I can grab a premium license, I’d definitely like to after how much time you’ve spent helping me.

Viewing 15 replies - 16 through 30 (of 31 total)
  • The topic ‘Issue with UPCs’ is closed to new replies.