Website Building » WooCommerce » How Do I Display Custom Fields in WooCommerce Product Page?

How Do I Display Custom Fields in WooCommerce Product Page?

Last updated on October 1, 2022 @ 5:25 am

Assuming you have already created your custom fields in WooCommerce, you can display them on the product page by adding this code to your product-single.php template:

$custom_fields = get_post_meta( $post->ID, ‘_custom_fields’, true );
foreach ( $custom_fields as $field ) {
echo $field[‘name’];
echo $field[‘value’];
}

This code should be added before the “add to cart” button on the product page. You can style the output using CSS. If you want to display the custom fields in a different location on the product page, you can use this code:

$custom_fields = get_post_meta( $post->ID, ‘_custom_fields’, true );
foreach ( $custom_fields as $field ) {
echo ‘

‘;
echo ‘‘ . $field[‘name’] .

‘‘;
echo ‘‘ . $field[‘value’] . ‘‘;
echo ‘

‘;
}

Conclusion:

How Do I Display Custom Fields in WooCommerce Product Page?

You can display custom fields on the product page by adding code to your product-single.php template. You can also use this code to display the custom fields in a different location on the product page.

Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.