woocomerce改变缩略图的样式

Published
May 5, 2022
浏览次数 :  0

// add filter for that targets only single product main image
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'new_product_image' ), 10, 2 );

/**
 * Set the correct image rendition for product page hero images.
 *
 * @param string $html the html we won't be changing.
 * @param int    $post_thumbnail_id the part we want to change to our image id.
 *
 * @return string the html with altered source
 */
function new_product_image( $html, $post_thumbnail_id ) {
    // New Image source set here (target the field where you have the image)
    $img_id = get_post_meta( get_the_id(), 'new_products_img_id', true );

    if ( ! empty( $img_id ) ) {
        // We substitute in our image id 
        $html = wc_get_gallery_image_html( $img_id, true );
    }
    return $html;
}

Top