How to Add GTIN Numbers On Products In WooCommerce

Add GTIN Numbers WooCommerce to Products

Are you searching for a way to add GTIN numbers to your site especially  GTIN number fields to WooCommerce products?

This article will guide you on how to use GTIN numbers on your WooCommerce site. Most retailers use a GTIN (Global Trade Item Number) to track and identify their products.

When you are setting up WooCommerce wholesale site, you need to consider adding GTIN numbers to products for easy tracking.

Add GTIN Numbers WooCommerce Products

The default version of WooCommerce does not support GTIN (UPC, EAN) product numbers out of the box.

UPC product code is used in North America, while EAN is used in Europe. Additionally, if you are selling books, you need to use the ISBN number. WooCommerce does not support these product code numbers. GTINs are used for internal tracking of the products in your WooCommerce store. They are required in product feeds for Google and Amazon.

There have been many requests made by WooCommerce store owners to get this feature added to the default version of WooCommerce, but it has not been added to the plugin. In this post, you will discover the  two methods that you can use to incorporate this functionality to your WooCommerce site.

Steps to Add GTIN Numbers  WooCommerce Using Code

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will add the GTIN Number functionality on Products in WooCommerce.
  3. Add the following code to the functions.php file:
/**
* Add Global Trade Identification Numbers (GTINs) to WooCommerce products.
*/

function woocommerce_render_gtin_field() {

$input   = array(
'id'          => '_gtin',
'label'       => sprintf(
'<abbr title="%1$s">%2$s</abbr>',
_x( 'Global Trade Identification Number', 'field label', 'my-theme' ),
_x( 'GTIN', 'abbreviated field label', 'my-theme' )
),
'value'       => get_post_meta( get_the_ID(), '_gtin', true ),
'desc_tip'    => true,
'description' => __( 'Enter the Global Trade Identification Number (UPC, EAN, ISBN, etc.)', 'my-theme' ),
);
?>
<div id="gtin_attr" class="options_group">
      <?php woocommerce_wp_text_input( $input ); ?>
</div>
<?php
}

add_action( 'woocommerce_product_options_inventory_product_data', 'woocommerce_render_gtin_field' );

/**
* Save the product's GTIN number, if provided.
*
* @param int $product_id The ID of the product being saved.
*/

function woocommerce_save_gtin_field( $product_id ) {
if (
      ! isset( $_POST['_gtin'], $_POST['woocommerce_meta_nonce'] )
       || ( defined( 'DOING_AJAX' ) && DOING_AJAX )
       || ! current_user_can( 'edit_products' )
       || ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' )
) {
     return;
}
$gtin = sanitize_text_field( $_POST['_gtin'] );
update_post_meta( $product_id, '_gtin', $gtin );
}
add_action( 'woocommerce_process_product_meta','woocommerce_save_gtin_field' );
  1. To see the outcome of this code you need access to the Dashboard menu, click on Products, and then select on any product and click on Edit as shown in the screenshot below. When the Edit Product Page opens, on the Products Data section, click on Inventory and you will see where you can insert the GTIN Number as shown in the images below.Products page

Then,Adding GTIN Numbers using code

Additionally, there is an alternative for the not-so-tech-savvy users, that involves the use of a plugin.

It is for those who are not familiar with customizing their site with code or maybe they do not want to mess up the coding structure of their site.

The plugin that we are going to use is the Product GTIN (EAN, UPC, ISBN) for WooCommerce plugin which you can download directly using this link here  It is available at the WordPress repo. To add this functionality, just follow these simple steps:

Steps to Add GTIN Numbers in WooCommerce Using a Plugin

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. Then, we are going to install the plugin that we have indicated earlier. If you have downloaded it using the link above, simply navigate to Plugins > Add New. After that, click on Upload Plugin and then Browse for the downloaded file as shown below:Uploading the downloaded plugin

To download it directly in the Admin Panel, simply navigate to Plugins > Add New. After that, you will need to do a keyword search for the plugin ‘Product GTIN (EAN, UPC, ISBN) for WooCommerce’. You need to install and activate it as shown below:downloading the plugin

  1. To see the outcome of this code you need access to the Dashboard menu, click on Products, and then select on any product and click on Edit as shown in the screenshot below. When the Edit Product Page opens, on the Products Data section, click on Inventory and you will see where you can insert the GTIN Number as shown in the images below.Products page

Then,Add GTIN Numbers WooCommerce using code

However, it is recommended that you make these changes in a staging environment so that you have the ability to make sure this is the functionality that you desire your site to have, without influencing your live site until you are ready to implement it.

Conclusion

In this post, we have highlighted two methods that you can add GTIN numbers in your WooCommerce site.

We have also outlined the importance of GTIN  Identification numbers in the products so that they can be recognized globally.

The first method is a developer-friendly solution that involves code, and the second one is a beginner-friendly method that involves the use of a plugin to easily add GTIN numbers to your WooCommerce store

Similar Articles

Comments are closed.