• Resolved Krzysztof

    (@koncak)


    Hi,
    I’m trying to import products with meta fields containing some array structure. My value in CSV file is:
    a:1:{i:0;a:5:{s:25:"ph_booking_resources_name";s:0:"";s:25:"ph_booking_resources_cost";s:0:"";s:32:"ph_booking_resources_auto_assign";s:2:"no";s:31:"ph_booking_resources_per_person";s:2:"no";s:29:"ph_booking_resources_per_slot";s:2:"no";}}

    but when I take a look into database I can see something like this (prefixed s:239: and quoted):
    s:239:"a:1:{i:0;a:5:{s:25:"ph_booking_resources_name";s:0:"";s:25:"ph_booking_resources_cost";s:0:"";s:32:"ph_booking_resources_auto_assign";s:2:"no";s:31:"ph_booking_resources_per_person";s:2:"no";s:29:"ph_booking_resources_per_slot";s:2:"no";}}"

    If I manually in database make the value looking like in CSV file every thing is working correctly.

    How can I force import process to insert such value as it is provided without any changes?

    Correct value in export XML looks like this:

    <wp:postmeta>
    <wp:meta_key><![CDATA[_phive_booking_resources_pricing_rules]]></wp:meta_key>
    <wp:meta_value><![CDATA[a:1:{i:0;a:5:{s:25:"ph_booking_resources_name";s:0:"";s:25:"ph_booking_resources_cost";s:0:"";s:32:"ph_booking_resources_auto_assign";s:2:"no";s:31:"ph_booking_resources_per_person";s:2:"no";s:29:"ph_booking_resources_per_slot";s:2:"no";}}]]></wp:meta_value>
    </wp:postmeta>

    Thanks,
    Krzysztof

    • This topic was modified 4 years, 6 months ago by Krzysztof.
    • This topic was modified 4 years, 6 months ago by Krzysztof.
    • This topic was modified 4 years, 6 months ago by Krzysztof.
    • This topic was modified 4 years, 6 months ago by Krzysztof.
Viewing 1 replies (of 1 total)
  • Thread Starter Krzysztof

    (@koncak)

    Solution is:

    <?php
    /*
    Plugin Name: Divide Meta Fields with Comma (Really Simple CSV Importer add-on)
    */
    
    add_filter('really_simple_csv_importer_save_meta', function($meta, $post, $is_update) {
        
        // serialize metadata
        $str_array = "";
        if (isset($meta['_phive_booking_availability_rules'])) $str_array = $meta['_phive_booking_availability_rules'];
        $meta_array = unserialize($str_array);
        $meta['_phive_booking_availability_rules'] = $meta_array;
        
        return $meta;
        
    }, 10, 3);
    • This reply was modified 4 years, 6 months ago by Krzysztof.
Viewing 1 replies (of 1 total)
  • The topic ‘How to import serialized value into custom meta field.’ is closed to new replies.