Aleš Sýkora / December 6, 2023 / 3 comments

WooCommerce gallery in Bricks dynamic data

Post summary: If you would like to use WooCommerce product gallery images in Bricks dynamic data – for example with Gallery module, then you find, that there is no option for that. The solution is simple – create custom function to get the images and then call it with echo. This can be used for Bricks carousel…

If you would like to use WooCommerce product gallery images in Bricks dynamic data – for example with Gallery module, then you find, that there is no option for that. The solution is simple – create custom function to get the images and then call it with echo.

This can be used for Bricks carousel too.

How to create Bricks Gallery with WooCommerce images

I don’t like the settings fot Bricks WooCommerce Gallery module and that’s why I rather use the base Bricks Gallery. Here is an example how to fill it with WooCommerce product images:

  1. Create a PHP function in Advanced Scripts or other snippet plugin
// this function return all product images - main and gallery
function woo_product_images_all() {
 global $product; 
 $attachment_ids = $product->get_gallery_attachment_ids();
 array_unshift($attachment_ids, $product->get_image_id());
 return $attachment_ids;
}
// this function return only product gallery images
function woo_product_images_gallery() {
 global $product; 
 $attachment_ids = $product->get_gallery_attachment_ids(); 
 return $attachment_ids;
}
Code snippet placed in WPcodebox 2
  1. Add the Bricks Gallery and fill it with echo:function
  1. You are done. Images will appear ASAP if you have enabled the dynamic data rendering in Bricks builder settings.

If you rather want to use the carousel instead of gallery, follow this steps:

  1. Create a PHP function in Advanced Scripts or other snippet plugin
// this function return all product images - main and gallery
function woo_product_images_all() {
 global $product; 
 $attachment_ids = $product->get_gallery_attachment_ids();
 array_unshift($attachment_ids, $product->get_image_id());
 return $attachment_ids;
}
// this function return only product gallery images
function woo_product_images_gallery() {
 global $product; 
 $attachment_ids = $product->get_gallery_attachment_ids(); 
 return $attachment_ids;
}
  1. Add the Bricks Carousel and fill it with echo:function and choose which function you want
  1. you are done, Images appears immediately.

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

3 comments

  • Hi Aleš

    Thanks for the nice tutorial. I would love to use the Product-Images in a query loop of Bricks Builder (would love to use a custom svg mask on the images). Is there also a possibility for this? How could I do this?

    Thank you for your great work.

    Best regards
    Thomas

  • Thanx. I spend half a day to make this f**g woo gallery_attachment_ids working!

Share Your Thoughts