Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
Created December 27, 2025 21:43
Show Gist options
  • Select an option

  • Save tdmrhn/5751f62a112a2da74624d3504b584cfc to your computer and use it in GitHub Desktop.

Select an option

Save tdmrhn/5751f62a112a2da74624d3504b584cfc to your computer and use it in GitHub Desktop.
Blocksy Change Product Card Swap Image With Custom Field
<?php
add_filter(
'blocksy:woocommerce:product-card:thumbnail:gallery-images',
function ($gallery_images) {
if (! is_product() && ! is_shop() && ! is_product_category()) {
return $gallery_images;
}
global $product;
if (! $product) {
return $gallery_images;
}
$hover_image_url = get_post_meta(
$product->get_id(),
'hover_image_url',
true
);
if (! $hover_image_url) {
return $gallery_images;
}
// Keep main image, inject hover image as second
return array_merge(
[$gallery_images[0]],
[
[
'url' => esc_url($hover_image_url)
]
]
);
},
20
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment