Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter merchantweb

    (@merchantweb)

    Ok, so after some more experimenting I decided to go into edit this product. From product data> inventory I confirmed that ‘Enable stock management at product level’ is checked. Then I notice there is a stock amount set to 0 on this same tab. This, in addition to the stock amounts set for each variation. *Note: I’m using WP All Import to import products and inventory. I wonder if this is causing something to not register between your plugin and my products?

    Anyway, after removing the stock of 0 on the main inventory tab so the field looks blank I updated the product and went to the category with sort by availability enabled and the product is now showing. Though another problem has shown its face and I don’t understand how I can kick all my products into gear automatically.

    Take a look at the list of products that shows when sort by availability is selected. The other products shown by availability are single products with no stock. Any ides on what is going on here?

    Thanks!

    Thread Starter merchantweb

    (@merchantweb)

    It looks like I’m going to be using this snippet until I can figure out why order by _stock performs that way… Stock status seems to be working better for me using the below code:

    add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
    
    function custom_woocommerce_get_catalog_ordering_args( $args ) {
      $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    
    	if ( 'stock' == $orderby_value ) {
    		$args['orderby'] = 'meta_value';
    		$args['order'] = 'asc';
    		$args['meta_key'] = '_stock_status';
    	}
    
    	return $args;
    }
    
    add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
    
    function custom_woocommerce_catalog_orderby( $sortby ) {
    	$sortby['stock'] = 'Stock Status';
    	return $sortby;
    }

    I will have to research the differences that led to my issues. I’m guessing this could be a common issue for others who are setup like me with 1000s of single products and variations.

    Could the above be integrated to your plugin? Maybe with this code as working code you can tell me what the difference is between it and yours or why it works for my case?

    Plugin Author Beka Rice

    (@bekarice)

    Hi @merchantweb, the import is indeed the issue. That stock meta for the parent product needs to be set, and the import most likely is not setting this meta. Since it’s not added, these products are not found when we sort by stock.

    You’ll either need to set the stock properly when imported, or bulk edit / quick edit your products to set it.

    The reason your snippet works is because it’s only looking for stock status — in stock / out of stock is always set. This plugin sorts by the stock value, which is not being set in your import. We don’t have plans to change this to stock status, as all this does is put all in-stock items first (not necessarily sorted by inventory), then all out of stock items.

    If that’s all you need, you can continue using your snippet and remove the plugin ??

    Cheers!

    designbygalvan

    (@designbygalvan)

    Hi @merchantweb,

    In what file did you use your snippet?

    I’m having the same issue. sorting by stock does not show my products in the shop page, also I’m using WP ALL IMPORTE and i have 1000s of productos.

    Here’s my shop https://www.divinajoyeria.com

    Cheers

    Thread Starter merchantweb

    (@merchantweb)

    Hi designbygalvan,

    I apologize for the super late reply and hope you were able to find the answer before now but for anyone still curious…

    Modify the functions.php file in your theme or child theme folder.

    I’m working on this again because there have been updates to WooCommerce and it changes the ability for this to work as I intended. Now you cannot purchase a product that is set to outofstock and allow backorder.

    Hoping to figure out the dependencies needed for my products to show up in sorting by stock qty as Beka has suggested would be better. I’ll be experimenting with WP All Import to include all necessary data on product creation. When I solve it I will post back with all data fields needed.

    Thanks for the input Beka and designbygalvan!

    Thread Starter merchantweb

    (@merchantweb)

    That stock meta for the parent product needs to be set, and the import most likely is not setting this meta. Since it’s not added, these products are not found when we sort by stock.

    You’ll either need to set the stock properly when imported, or bulk edit / quick edit your products to set it.

    Thanks so much, Beka! I will try that. ??

    • This reply was modified 8 years, 6 months ago by merchantweb.
    Thread Starter merchantweb

    (@merchantweb)

    Hi Beka,

    The Bulk edit does not work. The quick edit works when I update products individually. All I need to do is click quick edit and save (no changes needed). The variable products then become visible when sorting by stock status, however, when sorting by stock qty they disappear again. Do you have any more ideas on what is causing the data to not go through and how I can completely update a product or create one for that matter with wp all import that includes the necessary information to display on the front end when sorting by quantity for variations and simple products alike?

    Thanks so much for any help everyone!

    -MerchantWeb

    • This reply was modified 8 years, 4 months ago by merchantweb.
    Thread Starter merchantweb

    (@merchantweb)

    Posted an update to this below. Any suggestions?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Sort by Availability for Variable Products’ is closed to new replies.