• Resolved christianpon

    (@christianpon)


    Hi all,

    When using the built-in WooCommerce importer/exporter, the new field “GTIN, UPC, EAN, or ISBN” is not included. A snippet has been provided for export that works fine, see below: (Courtesy of @mujuonly and @serafinnyc)

    add_filter('woocommerce_product_export_column_names', 'add_custom_gtin_export_column');
    function add_custom_gtin_export_column($columns) {
    $columns['global_unique_id'] = 'GTIN/UPC/EAN/ISBN';
    return $columns;
    }

    add_filter('woocommerce_product_export_product_row', 'add_custom_gtin_export_row', 10, 3);
    function add_custom_gtin_export_row($row, $product, $product_id) {
    $gtin_value = get_post_meta($product_id, '_global_unique_id', true);

    $row['global_unique_id'] = !empty($gtin_value) ? $gtin_value : '';

    return $row;
    }

    I haven’t been able to tweak this to work also for import. Kindly asking for assistance resolving the issue.

    Many thanks in advance!
    Christian P.

Viewing 6 replies - 1 through 6 (of 6 total)
  • mujuonly

    (@mujuonly)

    @christianpon

    For importing, there is no need of a code snippet but a slight modification to the export code snippet is needed. Please see the updated code snippet below ( try an export after that ) and do an import with the exported file.


    add_filter('woocommerce_product_export_column_names', 'add_custom_gtin_export_column');
    function add_custom_gtin_export_column($columns) {
    $columns['global_unique_id'] = 'meta:_global_unique_id';
    return $columns;
    }

    add_filter('woocommerce_product_export_product_row', 'add_custom_gtin_export_row', 10, 3);
    function add_custom_gtin_export_row($row, $product, $product_id) {
    $gtin_value = get_post_meta($product_id, '_global_unique_id', true);

    $row['global_unique_id'] = !empty($gtin_value) ? $gtin_value : '';

    return $row;
    }
    Thread Starter christianpon

    (@christianpon)

    @mujuonly

    Works like a charm, many many thanks!

    technicalheadwear

    (@technicalheadwear)

    Excuse my questions. Where would you please this code snippet? I too would like to import/export this field using the native import/export function. I’m wondering why It wasn’t included when roling out the feature.

    Plugin Support Jonayed Hosen (woo-hc)

    (@jonayedhosen)

    Hi @technicalheadwear,

    Thank you for bringing this up!

    This issue is on our end, but I’m happy to share that it’s already been addressed and a fix will be included in an upcoming WooCommerce release. You can keep an eye on the WooCommerce changelog to confirm when the solution is rolled out: WooCommerce Changelog.

    Where would you please this code snippet??

    To add the code, you can use a third-party plugin like Code Snippets, which is user-friendly and avoids directly editing theme files. Alternatively, you can add the code to your theme’s functions.php file.

    If you choose this route, remember to create a backup of your site or use a child theme to prevent accidental issues with your main theme.

    I hope this helps!

    @jonayedhosen

    Thank you very much for this great reply. I have code snippet already installed. I’ll use your code until it’s natively released.

    Kind Regards,
    Edward

    Plugin Support Beauty of Code (woo-hc)

    (@beautyofcode)

    Hey Edward,

    Sounds like a plan!

    Feel free to start your own topic if you need any further help. ??

    Cheers!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.