Created
December 27, 2025 21:43
-
-
Save tdmrhn/5751f62a112a2da74624d3504b584cfc to your computer and use it in GitHub Desktop.
Blocksy Change Product Card Swap Image With Custom Field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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