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.
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
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
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.