Site icon Recharge Fashion

How To Extract / Get data cart product id from wp_usermeta woocommerce with MySQL

I can get the data cart for every user in wp_usermeta table from woocommerce, and I want to extract the product_id, variation_id and quantity from meta_value column (‘_woocommerce_persistent_cart_1’ meta_key), but the data is like this:

‘a:1:{s:4:”cart”;a:3:{s:32:”fdb1a5e7715f3a1f210683f643fd1378″;a:11:{s:3:”key”;s:32:”fdb1a5e7715f3a1f210683f643fd1378″;s:10:“product_id”;i:27907;s:12:“variation_id”;i:27908;s:9:”variation”;a:1:{s:36:”abc”;s:6:”100-ml”;}s:8:“quantity”;i:2;s:9:”data_hash”;s:32:”14990f0b52c6ffe0a3d7332e2b8d57d6″;s:13:”line_tax_data”;a:2:{s:8:”subtotal”;a:0:{}s:5:”total”;a:0:{}}s:13:”line_subtotal”;d:62000;s:17:”line_subtotal_tax”;i:0;s:10:”line_total”;d:49599;s:8:”line_tax”;i:0;}s:32:”1f1baa5b8edac74eb4eaa329f14a0361″;a:11:{s:3:”key”;s:32:”1f1baa5b8edac74eb4eaa329f14a0361″;s:10:“product_id”;i:1807;s:12:“variation_id”;i:0;s:9:”variation”;a:0:{}s:8:“quantity”;i:1;s:9:”data_hash”;s:32:”b5c1d5ca8bae6d4896cf1807cdf763f0″;s:13:”line_tax_data”;a:2:{s:8:”subtotal”;a:0:{}s:5:”total”;a:0:{}}s:13:”line_subtotal”;d:31406;s:17:”line_subtotal_tax”;i:0;s:10:”line_total”;d:25125;s:8:”line_tax”;i:0;}s:32:”d346c897e83ef2e8bcc44cc37800eb0b”;a:11:{s:3:”key”;s:32:”d346c897e83ef2e8bcc44cc37800eb0b”;s:10:“product_id”;i:28337;s:12:“variation_id”;i:28340;s:9:”variation”;a:1:{s:28:”def”;s:12:”zzz”;}s:8:“quantity”;i:1;s:9:”data_hash”;s:32:”31390d8dd6e19165f69831718b6a5b39″;s:13:”line_tax_data”;a:2:{s:8:”subtotal”;a:0:{}s:5:”total”;a:0:{}}s:13:”line_subtotal”;d:38000;s:17:”line_subtotal_tax”;i:0;s:10:”line_total”;d:30400;s:8:”line_tax”;i:0;}}}’

and if I add or remove an item from/to the cart, the data structure will change too (the array will reduce or increase), or maybe there is another way to extract the data? But I want to extract the data with MySQL to a table.

the result I want is

product_id variation_id quantity
27907 27908 2
1807 0 1
28337 28340 1

or maybe like this

product_id variation_id quantity product_id variation_id quantity product_id variation_id quantity
27907 27908 2 1807 0 1 28337 28340
Exit mobile version