In the Dokan plugin, when vendors want to bulk import products, they first need to upload images to the media library, copy their URLs, and map them manually in the CSV file before importing. This process is tedious and error-prone, as vendors can easily associate the wrong images with products.
To address this, I created a custom Dokan module to extend the WooCommerce product import process. My solution introduces a new step, Add Images, where vendors can drag and drop images for each product in a table-like interface. The process would look like this:
Vendors upload a CSV file (without image URLs) as usual. Map the CSV columns to WooCommerce product fields. In the new Add Images step, show the product data (e.g., Product Name, SKU) and a column for uploading images. Process the images, map them to products, and save them in the CSV file before final import. I’ve modified the WooCommerce product importer steps using the woocommerce_product_csv_importer_steps filter:
$new_steps = array(
'upload' => array(
'name' => __( 'Upload CSV file', 'woocommerce' ),
'view' => array( $this, 'upload_form' ),
'handler' => array( $this, 'upload_form_handler' ),
),
'mapping' => array(
'name' => __( 'Column mapping', 'woocommerce' ),
'view' => array( $this, 'mapping_form' ),
'handler' => '',
),
'add_images' => array(
'name' => __( 'Add images', 'woocommerce' ),
'view' => array( $this, 'add_images' ),
'handler' => '',
),
'import' => array(
'name' => __( 'Import', 'woocommerce' ),
'view' => array( $this, 'import' ),
'handler' => '',
),
'done' => array(
'name' => __( 'Done!', 'woocommerce' ),
'view' => array( $this, 'done' ),
'handler' => '',
),
);
$this->steps = apply_filters( 'woocommerce_product_csv_importer_steps', $new_steps );
My problem is with the add_images step. I need to access the parsed CSV data at this point to display product names and other data in a table so that images can be uploaded and matched to products.
Here’s what I’ve tried in my add_images function:
public function add_images(){
add_action('woocommerce_product_import_before_import', function ($importer) {
var_dump($importer);
// Access the importer object, e.g., $importer->file for the uploaded CSV file.
});
echo 'Adding Images';
}
and accept echoing 'Adding Imgaes` it does nothing till now.
Question: Which WooCommerce hook or filter should I use to access the parsed CSV data in my custom Add Images step?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742292901a4416536.html
评论列表(0条)