Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // WooCommerce - Set product image to category image
- remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
- add_action( 'woocommerce_before_single_product_summary', 'custom_show_product_images', 20 );
- function custom_show_product_images() {
- global $product;
- $product_id = $product->get_id();
- $cats = get_the_terms( $product_id, 'product_cat' );
- $cat = $cats[0]; // take the first category only
- $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
- $image = wp_get_attachment_url( $thumbnail_id );
- if ( $image ) {
- echo '<img src="'.$image.'" alt="'.$cat->name.'" />';
- }
- } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement