Display all WooCommerce product metadata in a meta box

/**
 * Adds and displays the "Product metadata" meta box.
 *
 * @see https://wpcodebook.com/woocommerce-product-metadata-meta-box/
 * @see https://developer.wordpress.org/reference/hooks/add_meta_boxes/
 * @see https://developer.wordpress.org/reference/functions/add_meta_box/
 * @see https://developer.wordpress.org/reference/functions/get_post_meta/
 */
add_action( 'add_meta_boxes', function ( $post_type, $post ) {
	add_meta_box(
		'wpcodebook-product-metadata-meta-box',
		esc_html__( 'Product metadata' ),
		function ( $post ) {
			echo '<pre>' .
				print_r( get_post_meta( $post->ID ), true ) .
			'</pre>';
		},
		'product'
	);
}, 10, 2 );

Leave a Comment