auto_map_columns( $headers ); } } // The importer only creates product categories for a user who may manage them. wp_set_current_user( 1 ); // The downloadable sample products link to files on another site. update_option( 'wc_downloads_approved_directories_mode', 'disabled' ); update_option( 'woocommerce_coming_soon', 'no' ); $csv = WC_ABSPATH . 'sample-data/sample_products.csv'; $headers = ( new WC_Product_CSV_Importer( $csv, array( 'lines' => 1 ) ) )->get_raw_keys(); $result = ( new WC_Product_CSV_Importer( $csv, array( 'parse' => true, 'prevent_timeouts' => false, 'mapping' => array( 'from' => $headers, 'to' => ( new Theme_Screenshots_Importer() )->map( $headers ) ), ) ) )->import(); foreach ( $result['failed'] as $error ) { echo 'Product import: ' . ( is_wp_error( $error ) ? $error->get_error_message() : 'failed' ) . "\n"; } // One guest order for the order confirmation page. $order = wc_create_order(); foreach ( array( 'hoodie-with-logo' => 1, 'beanie' => 2 ) as $slug => $qty ) { $product = get_page_by_path( $slug, OBJECT, 'product' ); if ( $product ) { $order->add_product( wc_get_product( $product->ID ), $qty ); } } $address = array( 'first_name' => 'Alex', 'last_name' => 'Sample', 'address_1' => '60 29th Street', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94110', 'country' => 'US', 'email' => 'alex@example.com', 'phone' => '555-0100', ); $order->set_address( $address, 'billing' ); $order->set_address( $address, 'shipping' ); $order->set_payment_method_title( 'Cash on delivery' ); $order->calculate_totals(); $order->set_status( 'processing' ); $order->save(); echo 'Imported ' . count( $result['imported'] ) . " products.\n";