admin管理员组文章数量:1333442
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?
本文标签:
版权声明:本文标题:wordpress - How to access parsed CSV data during custom WooCommerce product import steps in Dokan? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742292901a2448144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论