How can I optimize and shorten this code that I am using to display Woocommerce custom fields?
function fields() {
global $product;
$value1 = get_post_meta( $product->id, 'storage', true );
$value2 = get_post_meta( $product->id, 'delivery_date', true );
$value3 = get_post_meta( $product->id, 'mpn', true );
$value4 = get_post_meta( $product->id, 'color', true );
$value5 = get_post_meta( $product->id, 'sizes_available', true );
$value6 = get_post_meta( $product->id, 'country_of_origin', true );
if ( ! empty( $value1 ) ) {
echo '<div>Storage: ' . $value1 . '</div>';
}
if ( ! empty( $value2 ) ) {
echo '<div>Delivery: ' . $value2 . '</div>';
}
if ( ! empty( $value3 ) ) {
echo '<div>Manufacturer's product number: ' . $value3 . '</div>';
}
if ( ! empty( $value4 ) ) {
echo '<div>Color: ' . $value4 . '</div>';
}
if ( ! empty( $value5 ) ) {
echo '<div>Sizes: ' . $value5 . '</div>';
}
if ( ! empty( $value6 ) ) {
echo '<div>Country: ' . $value6 . '</div>';
}
}
add_action( 'woocommerce_after_shop_loop_item', 'fields', 10 );
There will be even more fields in the future so I would like to shorten it.