Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // add a gallery image to all products in a specific category
- // code goes in functions.php for your child theme
- // in this example, 12 is the category id and 2931 is the media library image id.
- add_filter('woocommerce_product_gallery_attachment_ids', 'add_gallery_image', 10, 2);
- function add_gallery_image($ids, $product) {
- $terms = get_the_terms( $product->post->ID, 'product_cat' );
- foreach ($terms as $term) {
- if ($term->term_id == 12) {
- $ids[] = '2931';
- break;
- }
- }
- return $ids;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement