Hello!
I was importing(WPALLIMPORT PRO) products from an excel file(google sheets) to my WordPress/WooCommerce website built on the Woodmart Theme(specifically, the Furniture 1 theme). But, not all products have to be “published”. Some products need to have a “draft” status. In my excel file, I have a column called “status”, with values either “1” or “0”. “1” for published products and “0” for products in draft. No matter what code I apply to the WPALLIMPORT function editor, it still does not work. Most of the time I get the following error: PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function update_product_status….
I have tried different variations(and different code) of the following code:
// Custom function to update product status during import
function update_product_status($id, $data, $import_id) {
try {
// Get the ‘status’ value from the imported data
$status = (isset($data[‘status’])) ? $data[‘status’] : ”;
// Check if the ‘status’ value is set and not empty
if ($status !== ”) {
// Convert ‘0’ to ‘draft’ and ‘1’ to ‘publish’
$new_status = ($status === ‘1’) ? ‘publish’ : ‘draft’;
// Update the product status
wp_update_post(array(‘ID’ => $id, ‘post_status’ => $new_status));
}
} catch (Exception $e) {
error_log(‘Error updating product status: ‘ . $e->getMessage());
}
}
// Hook the custom function to the appropriate action during the import
add_action(‘pmxi_before_post_import’, ‘update_product_status’, 10, 3);
Is it something related to the WoodMart theme that I am unaware of? Any help would be appreciated. If you need any additional info, then please ask me. Thank you!