-
suleski
Hi. I am trying to add my own Carousel to the Single Products. Ideally, I would like to display the Images selected under “Product Gallery” (meta key = _product_image_gallery). I am having a most difficult time doing this.
WooCommerce appears to be storing the images as IDs, but the GenerateBlocks Query Block v2 does not seem to enumerate through those IDs. Of course, I need the URLs – but first just prove out the IDs.
I have seen several forum posts here on a similar topic and George typically responds with some flavor of shortcode. I really do not want to use a shortcode – it is important for me to use the GenerateBlocks GUI to style instead of writing CSS for this.
I have been debugging this all day using hooks like render_block or generateblocks_query_loop_args trying to find a solution. Any ideas?
-
suleski
I put together a hacky workaround that hijacks the Query Block when Query Type is set to ‘Post Query’ (does not work with the desired ‘Post Meta’).
The filter I used is ‘generateblocks_query_wp_query_args’. I look at the classes associated with the Query Block to isolate the hijacking. Ultimately, I set $query_args[‘post__in’] to the list of IDs stored in the ‘_product_image_gallery’ Post Meta.
At this point, the Loop Item is actually being hit with something and I can largely proceed as I would expect using a GB Query Block.
Hope this helps someone.
If the GB team has any better ideas, please share. This is the best I could figure out after almost two days.
-
Alvind
Hi there,
Your workaround is actually the right general approach here.
The Post Meta query type expects the meta value to be an actual array. WooCommerce stores
_product_image_galleryas a comma-separated string of attachment IDs, so the Query block can’t loop through it directly.
- You must be logged in to reply to this topic.