last day (18 days later) » 

6:36 PM
0
A: WordPress query through Products variation stock

Sally CJWooCommerce product variations use the post type product_variation and they have the attributes saved in a metadata named attribute_pa_{term slug} such as attribute_pa_depth in your case. The attributes (which are terms) are not assigned as to the product as terms; i.e. not saved in the WordPress...

 
For the WP_Query you have mention post type 'product_variation' but I need to use post type 'product'. I have 10 thousands products and I have some filter in sidebar. I am filtering products through price, depth variation and few custom fields. All these products are variable but I am displaying products with their variations on shop page. This is completely a custom page. Let me know if you need any information and thank you so much for your time and help.
 
Can you re-explain what you need? Perhaps I misunderstood your question.. and despite the code may not (completely) help you, have you tried it?
 
Yes I tried this already before posting here but it was not working. I have a shop page where I am displaying all my products and I have filters on this page. We have price, depth and few custom product meta fields in my filter. On selection of depth value it is displaying filtered results correctly but the problem is that it is displaying products even with a 0 stock for that selected depth value. I want to display products which will have something in stock for that selected depth from a filter. So I want to filter through variations stock in my main WordPress query.
 
I actually meant the code in my answer. But anyway, can you post the current code you use which works for filtering the products by the depth value?
 
I have posted that in my question above. As I mention that it is working for me but it is displaying products with stock value of 0. This is what I do not want as I only want to display variable products which will have something in stock. I can attach a complete file if you want
 
6:36 PM
That would be helpful. Can you post it on Pastebin?
 
pastebin.com/x9Bqk1ev You can see this complete section. I added my code for filters and for a loop.
 
I don't see pa_depth in the code; but I do see pa_tread-depth. Is that the "depth" you're talking about?
And the code in your question, I'm not seeing it in the code you posted on Pastebin. Which one is it (in which lines) in the file?
 
Yes. I did not add complete query code there because it was a lot of code. Yes I have pa_tread-depth value as a variation
Again Thank you so much for your time and help.
 
6:52 PM
Is it possible for you to include only the code relevant to the depth attribute? I.e. Edit the file, remove other filters and include just the depth stuff, then repost on Pastebin. ? I could do it, but it would be quicker if you do it since you know well about the code.
 
Okay I will post WP query specific to that filter. Give me a moment please
https://pastebin.com/506ZYef7
This includes stuff related to that specific query
 
Ok thanks. I'll check your code, but it will take time and I'd be idle here, but will be here.
 
Okay No problem.
 
7:11 PM
Actually, can you export 3 to 5 of your products having the depth variations, both in stock and out of stock?
You can remove URLs/domain.. before you send the export file.
 
7:45 PM
Sorry, never mind. I think I see the issue now.
 
8:03 PM
Are you there, @Awan?
I've got a suggestion for you, if you have time for it now. Otherwise, we can continue discussing later.
 
8:16 PM
I've actually updated my answer. I hope that works for you. Let me know and do @-mention me if you reply here.
Bye for now.
 
 
2 hours later…
9:57 PM
@SallyCJ Yes it is fine but using this pagination does not work.So we will need to deal with another issue. You provided the solution but it is within loop. Can we somehow control this in wp query ?
 
10:25 PM
Now I think you have correct idea about this issue but instead of controlling this within loop, we need to control this in WordPress query
 
10:56 PM
Hey Awan
I'm not very sure about that WordPress query, but I'll try to see if it's possible - it might not be, but we'll see.
Btw, if you have time, would you please check the other question you posted before?.. I'm just really wondering if my answer helped you.. ;)
 
11:14 PM
Actually for that I have tried a different solution totally. I am using body for passing data which works for me. I can post my solution there as well.
But right now I am dealing with this issue and struggling to get this working as it is the last issue before launching this website.
@SallyCJ If you have any suggestion about this that would be great.
 
"pagination does not work" - sorry, are you sure? Do you have the pagination in the code you posted first on Pastebin - from the way you loop through the product variations for generating the radio buttons, I don't see how you are adding pagination there?
Ah, I see - about the other question. Yes, please do post your solution - but of course, later on. Just don't forget, ok? :D
But from what I can tell now, it might be possible to do that WordPress query, but I'm imagining it's going to be complex and may make things slow since you've got many database queries in your code.
I mean, the products (parent products) pagination should work just fine with your existing query. If there are variable products which have no variations which are in stock, then the variable products should be excluded from the results and the pagination would work as expected. Or am I misunderstanding something?
 

  last day (18 days later) »