Support » Plugin: WooCommerce Cart Stock Reducer » Product_visibility outofstock tag

  • Hi @jamesgol,

    I’m trying to change the “product_visibility” taxonomy every time the product goes out of stock, or in stock. This is so out of stock products won’t be displayed at the shop, and only in stock products are displayed.

    Currently, the plugin seems to only set the product stock status to “out of stock”, but doesn’t add the “outofstock” tag to “product_visibility”, which causes the product is still being displayed, but with some errors.

    EDIT: Forgot to tell you, I set “hide out of stock products” enabled at WooCommerce, so that’s why the errors pop up when an out of stock product being displayed. Currently using WooCommerce 3.4.4.

    Can you tell me where I can insert my code to do this?

    wp_set_object_terms( $id, 'outofstock', 'product_visibility', true );

    Thanks,
    Dicko

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author James Golovich

    (@jamesgol)

    What errors are popping up when “hide out of stock products” is checked? I’d rather fix a problem rather than applying a band aid.

    Warning: array_unique() expects parameter 1 to be array, null given in /home/konsephe/public_html/luxofood/wp-includes/post-template.php on line 545
    
    Warning: join(): Invalid arguments passed in /home/konsephe/public_html/luxofood/wp-includes/post-template.php on line 423
    class="" >

    I use WPBakery, I’m not sure if WPBakery is the one not detecting the “outofstock” tag, but I know to make the product not listed from the shop is just to “update” the product again from edit page with no changes, or if done by code, add “outofstock” tag to “product_visibility”.

    Thanks,
    Dicko

    Plugin Author James Golovich

    (@jamesgol)

    I don’t have WPBakery at all, but trying on the Storefront theme I couldn’t reproduce this issue.

    What theme are you using? I wonder if its WooCommerce templates aren’t following the recommended processes.

    Edit: There could also be a caching issue, so when you save the item it clears the cache. Are you using any caching?

    Thanks for the tip, you’re correct James, turned out it’s because of the outdated WooCommerce templates. The theme I’m currently using is Yith Panarea theme, it’s an old theme. Sadly, if I update the WooCommerce templates, my site is going haywire with the visual.

    I’m going to switch to another theme. For now, since the site is already live, I need to give it a temporary fix, until I can switch to the new theme. Is there a way for me to do this?

    Thanks,
    Dicko

    Plugin Author James Golovich

    (@jamesgol)

    Probably your easiest bet would be to roll back WooCommerce to something pre 3.x or get your theme updated.

    There really isn’t a good place to call wp_set_object_terms() since there is so much that is happening dynamically with this plugin.

    The theme itself is already not updated anymore, and it’s going to be a hassle to roll back to previous WooCommerce version as I’ve made the “outofstock” tag modification to several other plugins.

    I’ll have to figure out a way to handle this, or I might have to try other alternatives for this purpose.

    Anyway, thanks a lot for your help James, appreciated it. I’ll mark this issue as resolved.

    Thanks,
    Dicko

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Product_visibility outofstock tag’ is closed to new replies.