Add EAN value to list of attributes under "Additional Information" tab

This article explains how to add the product's EAN value (if it exists) to the table under the Additional Information tab:

Add EAN value to table under Additional Information tab.
1

Create a custom plugin

If you haven't done so already, create a custom plugin.

2

Add custom code

Add the following custom code to your custom plugin.

/**
 * Add product's EAN value to table in "Additional Information" tab if EAN exists.
 */
add_filter( 'woocommerce_get_product_attributes', 'mycode_display_ean_in_product_attributes_table', 20 );
function mycode_display_ean_in_product_attributes_table( $attributes ) {

	/**
	 * Edit the following 3 variables to suit your needs.
	 */
	$label    = 'EAN'; // The label for this attribute.
	$key      = 'ean'; // The product field whose value will be returned.
	$position = '10';  // The position the attribute will appear in table.

	global $product;

	if ( ! dfrpswc_is_dfrpswc_product( $product->id ) ) {
		return $attributes;
	}

	$postmeta = get_post_meta( $product->id, '_dfrps_product', true );

	if ( ! isset( $postmeta[ $key ] ) ) {
		return $attributes;
	}

	$attribute = array(
		'name'         => $label,
		'value'        => $postmeta[ $key ],
		'is_visible'   => '1',
		'is_taxonomy'  => '0',
		'is_variation' => '0',
		'position'     => $position,
	);

	$attributes[ 'dfrpswc_' . $key ] = $attribute;

	return $attributes;
}
	

Still need help? Contact Us Contact Us