Home Forums WoodMart support forum WOODMART / WPALLIMPORT PRO / Creating a function that sets the product status

WOODMART / WPALLIMPORT PRO / Creating a function that sets the product status

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #536927

    webguana.com
    Participant

    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!

    #537078

    Hung Pham
    Keymaster

    Hi webguana.com,

    Thanks for reaching to us.

    1. Custom function

    Unfortunately, customization is out of basic support. Thanks for your understanding.

    2. Status

    Please refer to articles below for more details:

    https://www.wpallimport.com/documentation/image-options/
    https://www.wpallimport.com/documentation/how-to-import-wordpress-posts/

    Regards,

Viewing 2 posts - 1 through 2 (of 2 total)