Skip to content

Instantly share code, notes, and snippets.

@StefsterNYC
Last active September 12, 2024 15:00
Show Gist options
  • Save StefsterNYC/ffeeac6991fff6ef2dc987ad77e30eae to your computer and use it in GitHub Desktop.
Save StefsterNYC/ffeeac6991fff6ef2dc987ad77e30eae to your computer and use it in GitHub Desktop.
<?php
/**
* @snippet Adds a column for the new GTIN input field on Products so when you export the column shows
* @author Serafin Tech
* @compatible WooCommerce 9+
* @website https://serafintech.io
*/
// Add the GTIN/UPC/EAN/ISBN to the export column names
add_filter('woocommerce_product_export_column_names', 'add_custom_gtin_export_column');
function add_custom_gtin_export_column($columns) {
// Add a new column for GTIN/UPC/EAN/ISBN
$columns['global_unique_id'] = 'GTIN/UPC/EAN/ISBN';
return $columns;
}
// Add the GTIN/UPC/EAN/ISBN data to the export rows
add_filter('woocommerce_product_export_product_row', 'add_custom_gtin_export_row', 10, 3);
function add_custom_gtin_export_row($row, $product, $product_id) {
// Get the GTIN/UPC/EAN/ISBN value from the product meta
$gtin_value = get_post_meta($product_id, '_global_unique_id', true);
// Add the value to the row in the 'global_unique_id' column
$row['global_unique_id'] = !empty($gtin_value) ? $gtin_value : ''; // Fallback for missing values
return $row;
}
@StefsterNYC
Copy link
Author

StefsterNYC commented Sep 12, 2024

The new GTIN input field doesn't show in product export. This allows you to export so that the values set in that field show in your export file. Use at your own risk. Tested up to 6.6.2 core and WooCommerce 9.3 Code should be added to your functions.php file of your child theme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment