'Exporting Serialized ACF Field Groups with Import Export Suite for WooCommerce

I am trying to export my products with WP All Export Pro plugin. I also used the ACF plugin to show details like specifications on my products. However, when exporting products, it exports serialized. I also tried exporting using the Import Export Suite for WooCommerce and ended up with the same result.

Serialized example data below

a:4:{s:12:"pa_waist-pad";a:6:{s:4:"name";s:12:"pa_waist-pad";s:5:"value";s:0:"";s:8:"position";i:0;s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:19:"pa_d-ring-placement";a:6:{s:4:"name";s:19:"pa_d-ring-placement";s:5:"value";s:0:"";s:8:"position";i:1;s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:17:"pa_leg-connection";a:6:{s:4:"name";s:17:"pa_leg-connection";s:5:"value";s:0:"";s:8:"position";i:2;s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}s:7:"pa_size";a:6:{s:4:"name";s:7:"pa_size";s:5:"value";s:0:"";s:8:"position";i:3;s:10:"is_visible";i:0;s:12:"is_variation";i:1;s:11:"is_taxonomy";i:1;}}

I deserialized them with the code below.

function data_deserialize_csv($value)
{
$output = '';
$data = unserialize($value); 
print_r($data);$data = reset($data);
return $data['specs_product'];

}

The output of the above code is as follows

Array


[header] => 

[caption] => 

[body] => Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [c] => Attachment Points: 




                    )

                [1] => Array
                    (
                        [c] =>  1 dorsal D-ring
                    )

            )

        [1] => Array
            (
                [0] => Array
                    (
                        [c] => Weight:  

                    )

                [1] => Array
                    (
                        [c] => 3.7 lbs. (1.7 kg)

I just need values like weight in this output. For example;

Weight:130kg,Height:130cm,Attachment Points:1 dorsal D-ring

UPDATE 1

When I use the code below

function data_deserialize_csv($value)
{
$data = unserialize($value); 
unset ($value);
return implode( ',', $data );   
print_r ($data);

It gives the following output

Array,Array,Array,Array,Array,Array

Update 2

When I use the code below

function data_deserialize_csv($valuess)
{
$data = unserialize($valuess);
foreach ($data as $key => $data) {
$output= $key." =>".$data.","; }
unset($value);
return $output;

}

It gives the following output

pa_leg-connection =>Array,



Solution 1:[1]

You can use the below code snippet with the Import Export Suite for WooCommerce to export the product data in a custom format.

add_filter('wt_batch_product_export_row_data', 'wt_batch_product_export_row_data_acf', 10, 2);

function wt_batch_product_export_row_data_acf($row, $product) {

    if (isset($row['meta:specs_product']) && !empty($row['meta:specs_product'])) {
        $acf_data = json_decode($row['meta:specs_product']);
        if (!empty($acf_data)) {
            $acf_string = '';
            $acf_string .= "Weight:" . $acf_data->b[1][1]->c;
            $acf_string .= ', ';
            $acf_string .= "ANSI Weight Capacity:" . $acf_data->b[2][1]->c;
            $row['meta:specs_product'] = $acf_string;
        }
    }
    return $row;
}

Change the key as per your requirements.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1