-
swissky
Hey
Would it be possible to show in query loop variations of woocommerce products? Like different colors?
-
George
Hello. Are your attributes global ones or product specific ones?
-
swissky
Product specific. Like in the screenshot showing two products with there different color options
-
George
Use this code to create a new custom dynamic tag for the Color variations you have created:
/** * Register Product Colors Dynamic Tag */ function register_product_colors_dynamic_tag() { if (!class_exists('GenerateBlocks_Register_Dynamic_Tag')) { return; } new GenerateBlocks_Register_Dynamic_Tag( [ 'title' => __('Product Colors', 'generateblocks'), 'tag' => 'product_colors', 'type' => 'post', 'supports' => ['source'], 'return' => 'product_colors_callback', ] ); } add_action('init', 'register_product_colors_dynamic_tag'); /** * Product Colors Callback * * @param array $options The options. * @param object $block The block. * @param object $instance The block instance. * @return string */ function product_colors_callback($options, $block, $instance) { if (!function_exists('wc_get_product')) { return ''; } $product = wc_get_product(get_the_ID()); if (!$product || !$product->is_type('variable')) { return ''; } $colors = $product->get_attribute('Color'); if (!$colors) { return ''; } // Replace pipes or commas with slashes $colors = str_replace(' | ', ' / ', $colors); $colors = str_replace(', ', ' / ', $colors); return GenerateBlocks_Dynamic_Tag_Callbacks::output($colors, $options, $instance); }In your query loop, insert a GB text block and open dynamic tags. The last entry from the Post is called Product Colors.

Select that and check in the front end.
-
swissky
Thank you. Will that also show then the Color Variation Picture, if set?
-
George
No, it will also show
Red / Bluefor example, as you stated in your image. -
swissky
Ok, but is there an way that images and price also gets shown then for the right variation? Also the correct link to that variation?
-
George
Sorry but that would require custom development which is out of scope of the current support forum. Hope you understand!
- You must be logged in to reply to this topic.