• Hi, I need to import 6.5k products. I am using code below but I can upload only 400 products and then time out … what should I need to do ?

    $xml_response = simplexml_load_file('as.xml');
    
    foreach($xml_response as $xml){
        $my_post = array(
            'post_title'    => (string) $xml->brand." ".(string) $xml->description,
            'post_content'  => (string) $xml->description,
            'post_status'   => 'publish',
            'post_author'   => 1,
            'post_type' => 'product'
        );
    
        $id = wp_insert_post( $my_post );
        wp_set_object_terms( $id, array(6), 'product_cat' );
        wp_set_object_terms( $id, 'product_type_custom', 'product_type' );
    
        update_post_meta($id, "_sku", (string) $xml->sku);
        update_post_meta($id, "_price", (string) $xml->price);
        update_post_meta($id, "_regular_price", (string) $xml->price);
        update_post_meta($id, "_manage_stock", 'yes');
        update_post_meta($id, "_stock_status", 'instock');
        update_post_meta($id, "_stock", (string) $xml->qty_available);
        update_post_meta($id, "_visibility", 'visible');
        update_post_meta($id, "_downloadable", 'no');
        update_post_meta($id, "_virtual", 'no');
        update_post_meta($id, "_featured", 'no');
        update_post_meta($id, "_backorders", 'no');
    
        update_post_meta($id, "_retread", (string) $xml->retread);
        update_post_meta($id, "_baseprice", (string) $xml->Baseprice);
        update_post_meta($id, "_weight_bruto", (string) $xml->weight_bruto);
    }

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • I use WP-All-Import which supports XML. It allows iterative imports so your timeouts problem should be resolved. It is a premium plugin but it worth its weight in gold.

    https://www.wpallimport.com/

    Thread Starter andisman

    (@andisman)

    Thanks, but I need my own code because it will be with cronjob and will be updating products… So I need to solve the problem.

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    You can split the XML into small parts. Since this is not an issue with WooCommerce, it’s a lot of data for your server process at once, so you need to make easy for your server or increase server memory and etc.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I need to import 6.5k products from xml file’ is closed to new replies.