Home Forums Plugins Product Importer Deluxe [Resolved] Custom fields import manipulation

This topic contains 3 replies, has 2 voices, and was last updated by  Michael Visser 2 years, 3 months ago.

Welcome to our community support forums! We're here to help - but if you have an urgent request for a Pro Plugin, you will get a prioritised response through our Premium Support page.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #46486

    Dima
    Participant

    Hello Michael,
    Some time ago you gave me a snippet to include some hooks for importing custom fields. Particular I am talking about ‘woo_pd_create_product_addons’. My question is this: Inside the function with this hook is there a way to know if the product is being imported as new or is this product being updated (merged) ?
    I need this to do some manipulation on certain field depending on this.
    Thanks

    #46490

    Michael Visser
    Keymaster

    Hi Dima, good question. Just to clarify the woo_pd_create_product_addons WordPress Filter is only accessed when importing new Products while woo_pd_merge_product_addons is only accessed when merging Product changes.

    You could detect this state earlier by accessing the WordPress Filter woo_pd_prepare_product and accessing the $import and $global arguments passed as part of that WordPress Filter.

    For instance while using the woo_pd_prepare_product WordPress Filter:

    // Merging
    if( $import->import_method == ‘update’ ) {
    // Do something only when merging Products
    }
    if( $import->import_method == ‘new’ ) {
    // Do something only when importing new Products
    }

    Does this help? Feel free to open a Support ticket if required or let me know what point in the import process you want to make the modifications

    https://www.visser.com.au/premium-support/

    #46495

    Dima
    Participant

    Ok so I got into this a bit:
    1) woo_pd_prepare_product does not exist.
    So I looked into “woo_pd_merge_product_addons” which needs to be followed by “woo_pd_merge_product_log_addons”. You also make comparison if new value is different from old.
    So we need to load existing product values fist using “woo_pd_merge_product_data_addons”.
    I think you might want to add these to that snippet/tutorial on how to add custom fields to the import. Coz I didn’t know that there are different hooks for merging.

    BTW I made a simple solution so that I’ll not need to write the custom fields array on each hook function. So I made a simple function that I can call and it gives me the fields. I only need to add/edit them in one place.

    function alo_import_product_fields( $fields ) {
    $woo_ped_addon_fields = array();
    $woo_ped_addon_fields[] = array(
    ‘name’ => ‘newprod_date’,
    ‘label’ => ‘New Product Date’,
    ‘acf’ => true,
    ‘group_open’ => ‘<optgroup label=”Extra Fields”>’
    );
    $woo_ped_addon_fields[] = array(
    ‘name’ => ‘prod_type_abnab’,
    ‘label’ => ‘Product Type ab/nab’,
    ‘acf’ => true,
    );
    $woo_ped_addon_fields[] = array(
    ‘name’ => ‘wc_productdata_options’,
    ‘label’ => ‘AB/NAB Fields’
    );

    $fields = array_merge($fields, $woo_ped_addon_fields);

    return $fields;
    }

    Maybe you can use it.

    #46659

    Michael Visser
    Keymaster

    Hi Dima, just marking this one as resolved. I’ll get this code snippet up on the site to help others, thanks Dima! 🙂

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

The topic ‘[Resolved] Custom fields import manipulation’ is closed to new replies.