0

Trying to Store GTIN numbers in WordPress Database via WooCommerce CSV Import

In Excel I created my CSV in which there is a column called meta:wpseo_global_identifier_values

Through excel formulas I have created the value below with the dummy GTIN 1111111111111 to match how it is stored in the database table _postmeta

a:6:{s:5:"gtin8";s:0:"";s:6:"gtin12";s:0:"";s:6:"gtin13";s:9:"1111111111111";s:6:"gtin14";s:0:"";s:4:"isbn";s:0:"";s:3:"mpn";s:0:"";}

Then from the excel file, I generate the CSV file.

However after I import the CSV file and check the database I find that the data is input as below (with the extra characters s:134:" in the beginning and "; the end) and as a result, the GTIN is not visible on the website backend.

s:134:"a:6:{s:5:"gtin8";s:0:"";s:6:"gtin12";s:0:"";s:6:"gtin13";s:9:"1111111111111";s:6:"gtin14";s:0:"";s:4:"isbn";s:0:"";s:3:"mpn";s:0:"";}";

When I manually remove the extra characters the value is successfully stored and visible on the website backend.

I have tried to understand why this is happening but to no avail, does anyone have any idea why this might be so?

Thanks

3
  • Give this a try - wordpress.org/plugins/product-import-export-for-woo Commented Apr 14, 2020 at 7:28
  • Thanks but the plugin gave an error when it got to import the meta:wpseo_global_identifier_values Commented Apr 14, 2020 at 10:49
  • The problem is you're trying to create a serialized string and the values are incorrect. For example, in this part here: s:9:"1111111111111", I'm going to explain what this all means: - s: string - 9: length - "1111111111111": value So, you can see that the length is not correct. It should be 13, making that part of the serialized string look something like: s:13:"1111111111111" Commented Apr 14, 2020 at 13:50

1 Answer 1

0

Update:

Thanks to a good friend we found a temporary hack that works around the issue until the team at Yoast develop a more straightforward way of importing these global identifiers through the native woocomemrce importer.

Basically after each CSV import run this SQL query.

UPDATE _postmeta SET meta_value = TRIM("\";" FROM substring(meta_value, locate("{", meta_value) -4, length(meta_value) -4)) WHERE meta_key = 'wpseo_global_identifier_values' and SUBSTRING(meta_value, 1, 7) = 's:134:"'

Changes this:

s:134:"a:6:{s:5:"gtin8";s:0:"";s:6:"gtin12";s:0:"";s:6:"gtin13";s:13:"1111111111111";s:6:"gtin14";s:0:"";s:4:"isbn";s:0:"";s:3:"mpan";s:0:"";}";

to this:

a:6:{s:5:"gtin8";s:0:"";s:6:"gtin12";s:0:"";s:6:"gtin13";s:13:"1111111111111";s:6:"gtin14";s:0:"";s:4:"isbn";s:0:"";s:3:"mpan";s:0:"";}

And GTIN value is added to the products.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.