WooCommerce: write featured image dimensions to custom fields in product’

The key here is to use the save_post hook and have it only run the code when the post type is product (or whatever your product post type is).

Here’s the code — I made the assumption that you want the full size of the featured image:

add_action( 'save_post', 'save_product_featured_image_dimensions' );

function save_product_featured_image_dimensions( $post_id ) {

    if ( get_post_type( $post_id ) != 'product' ){
        return;
    }

    $post_thumbnail_id = get_post_thumbnail_id( $post_id );
    $attachment = wp_get_attachment_image_src( $post_thumbnail_id, 'full' );

    if ( $attachment ) {
        $width = $attachment[1];
        $height = $attachment[2];
    }

    update_post_meta( $post_id, 'product_featured_image_width', $width );
    update_post_meta( $post_id, 'product_featured_image_height', $height );

}

Also, you probably know this, but it seems worth mentioning — you can of course also grab the image dimensions of a product’s featured image without saving those to the metadata of the product, using code similar to the above. But I’m assuming you want to do something special that would require the values to be in the post meta.