Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • A little late, but here is a fix. Add this to your theme’s functions.php

    add_filter('option_sm_options', 'unique_id_filter_hidden_products', 10, 2);
    
    function unique_id_filter_hidden_products($value, $option){
      
       global $wpdb;
      $results = $wpdb->get_results(
        "SELECT post_id
        FROM $wpdb->postmeta
        WHERE meta_value='hidden'
        and meta_key='_visibility'"
      );
    
        $results = wp_list_pluck($results, 'post_id');
        $value['sm_b_exclude'] = array_unique(array_merge($value['sm_b_exclude'], $results));
    
        return $value;
    }
    Thread Starter Jigoossen

    (@jigoossen)

    Ok, I’ve figured it out. The issue was that all these products were imported to woocommerce and I thought I had verified on import that products with 0 quantity were also set to “Out of Stock”. So what was happening here was that all the products with no quantity were set to “In Stock”.

    Even though I found the workaround, it seems like odd behavior for Woocommerce. What appears to be happening is:
    1. For actual display of products it is checking _stock (i.e. quantity in stock)
    2. But for pagination it is checking _stock_status (i.e. “In Stock”, “Out of Stock”)

    I could understand deciding to base display on one or the other, but not inconsistently like this.

    Since I have so many products that had zero inventory, but were marked as “In Stock” I came up with a mysql query to execute on the database.

    First, as a precaution I checked it with a LIMIT of 1:

    UPDATE wp_postmeta SET meta_value='outofstock'
    WHERE post_id IN (
    	SELECT t2.post_id FROM ( SELECT t1.post_id FROM wp_postmeta t1 WHERE t1.meta_key="_stock" AND t1.meta_value='0') t2
    	) AND meta_key='_stock_status' LIMIT 1

    then I removed the limit:

    UPDATE wp_postmeta SET meta_value='outofstock'
    WHERE post_id IN (
    	SELECT t2.post_id FROM ( SELECT t1.post_id FROM wp_postmeta t1 WHERE t1.meta_key="_stock" AND t1.meta_value='0') t2
    	) AND meta_key='_stock_status'

    Just a thought, but you don’t happened to be covering the lines up by using the same numbers in the different if statements? Try an error_log("color") in each if statement just to make sure the problem is the if statements instead of the line drawing itself.

    Thread Starter Jigoossen

    (@jigoossen)

    Yes, it still happens on twenty sixteen. Acts the same way.
    I get this behavior everywhere: local, dev subdomain, live site…

    • This reply was modified 9 years, 2 months ago by Jigoossen.
    Thread Starter Jigoossen

    (@jigoossen)

    Ok, all the images have uploaded and the infinite redirect is no longer happening, but this display problem is still there.

    Thread Starter Jigoossen

    (@jigoossen)

    Sorry, I got impatient, and posted this before those images were uploaded. The reason that is happening is because I have the .htaccess setup to access the live site if anything in wp-conent/uploads is missing in the dev site. (prevents the royal pain of keeping uploads synced since they are not in git repo)

    <IfModule mod_rewrite.c>
      RewriteEngine on
    
      # Attempt to load files from production if
      # they're not in our local version
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule wp-content/uploads/(.*) \
        https://www.theoldhardwarestore.com/wp-content/uploads/$1 [NC,L]
    </IfModule>

    And I actually have the .htaccess in my git repo, so that is also in my production site .htaccess and the images are currently missing there too. So that’s the cause of infinite redirect. This is all because of a blunder I made earlier today, but unrelated to this product display issue. I was having that issue before the image issue(which I am fixing).

    What kind of code do you have inside the if statements? The code exactly as you have above would not “jump right out” anywhere. You must have some kind of return in your if statements causing it to leave the function this is in.

Viewing 7 replies - 1 through 7 (of 7 total)