Tell us what you are trying to do?
I have made a custom woocommerce product archive. It should sort by stock status (and then by product name), so that in-stock items appear first, and then out-of-stock items. I saw a similar forum topic where the user was told to change a setting under toolset > settings > woocommerce, but I don't see that setting in my admin. This archive was originally created in Views, but I am now running Blocks, so I don't know if that's part of the issue.
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site?
hidden link
Hello and thank you for contacting Toolset support.
The WooCommerce options have been removed since then. Now, you need to, first, disable the default WooCommerce sorting. Then you would be able to sort the products archive using the stock status custom field. If you can't choose the _stock_status custom field, you will need to activate it in Toolset->Settings -> Frontend Content -> Hidden custom
I hope this helps. Let me know if you have any questions.
Right, thanks, I guess my question is how to disable the default Woocommerce sorting.
You can disable it in the Toolset->Settings->WooCommerce(tab). Please note that this action is irreversible, once disabled, it cannot be enabled anymore. Check this screenshot hidden link
That means that the WooCommerce default sorting order has already been disabled. Now the order will be the one defined on the archive template.
If you are still encountering any issues with it, allow me temporary access to your website, so I can check this closely. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
The archive is correctly configured, but the order is still applied by post_date. This is the underlying SQL query hidden link
It is most probably caused by a compatibility conflict with the theme or another plugin. I wanted to check it but I am afraid I may break the staging site. I will need sFTP access to recover the site if crashed and continue my debugging. Please double-check the sFTP access, I could not log in with them.
I checked with this new password, and was able to log in:
A9qg7bDHuBgU
Thank you, the credentials worked for me. However, even with only the Toolset plugins, and WooCommerce, the issue is still reproducible. The archive is also assigned to the products post type archive, but it is not being used on the frontend. Something odd is happening. Maybe from the drop-in or must-use plugins.
I'll need to take a copy of your website and analyze it locally. If I don't find the cause of the issue, I'll transfer the copy to our 2nd Tier for further analysis. Once we get it resolved, we'll delete our copy of your website. Do you allow me to take the copy?
Yes that's fine, but I don't understand what you mean that it's not being used on the front end. There is another archive called Custom Products Archive, which is not being used currently, but the Toolset Products Archive is assigned to Products, and is being used on the front end. If you need a reminder of what the site looked like before you started troubleshooting, you could look at our live production site at windstoneeditions.com. Thanks for your help.
I meant that the products post archive, which is the store page, is not using the archive template. It displays the products categories, which is, I believe a default WordPress feature. The archive is being used for category archives though.
I tried to take a copy yesterday, using Duplicator, but it fails. The website is really heavy. I then used All In One Migration and it prepared the copy in around 4h, giving a +3Gb copy. Today, I tried to build it, and it took, roughly, 8h.
I'll be on my weekend tomorrow and Thursday, but I'll try to work for a couple of hours to check this and to escalate it to our 2nd Tier if I can't fix it. I'll keep you updated.
My apologies for not getting back to you earlier, I found the time to work this Wednesday, but I was not able to write back. The issue seems to be a bug with WooCommerce Blocks, and I was able to reproduce it on a clean install. Product archives always get sorted by post_date whatever sorting options we choose. You can check it on my test site here hidden link
I am escalating this to our 2nd Tier for another evaluation. In the meantime, I tried a workaround on your website and it seems to work. The workaround is a custom code that has a higher priority and changes the order of the archive:
if ( function_exists('is_product_category') ) {
function my_change_products_order( $query ){
if ( ! is_admin() && ( is_product_category() || is_product_tag() ) && $query->is_main_query() ) {
$query->set('meta_key', '_stock_status' );
$query->set('orderby', 'meta_value' );
}
}
add_action( 'pre_get_posts', 'my_change_products_order', 10000000000 );
}
Please check here and confirm if that works for you hidden link
Please note that I have switched theme and disabled plugins during my debugging. Reactivate them and check again.
Yes, that is working—thank you! I don't see the code in functions.php. Where did you put it? I would like to use it on my live site while we wait for the more permanent fix.
I added it to the Toolset Custom code section in Toolset->Settings->Custom code(tab). Make sure that the snippet is active for Front-end and AJAX calls. Check this screenshot hidden link
Alternatively, because you are using a child theme, you can add it to the child theme's functions.php file.
Let me know if that would fix the issue for the live site.