From 1a309856c3162b4a14db9fba7bdb8f32dbabfc57 Mon Sep 17 00:00:00 2001 From: axelmm Date: Mon, 20 Nov 2017 02:09:49 +0100 Subject: [PATCH] Access to importer parameters - DRY Access (read only) to params can be required in many cases when you're playing with importing. In my case it was extending importer with filters and actions (procedural way - within original csv importer process) but it relates to objective way (extending importer class), too. I wanted to know if 'update_existing' flag is set (other way than $_POST values) within filter 'woocommerce_product_importer_parsed_data' in parse/expand loop (called from class-wc-product-csv-importer.php 'set_parsed_data' method). Unfortunately this (and similiar) filter doesn't receive importer instance, only row data (raw, parsed and product object). Thanks to https://github.com/woocommerce/woocommerce/pull/15796 we have 'woocommerce_product_importer_formatting_callbacks' filter receiving importer instance. Unfortunately importer '$params' field is not accessible (protected in abstract). This PR resolves this simple problem - we can get this flag (and other params) before importing loops, processing rows etc. --- includes/import/abstract-wc-product-importer.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/import/abstract-wc-product-importer.php b/includes/import/abstract-wc-product-importer.php index e5ff902821f..f98ea8ef8ca 100644 --- a/includes/import/abstract-wc-product-importer.php +++ b/includes/import/abstract-wc-product-importer.php @@ -125,6 +125,15 @@ abstract class WC_Product_Importer implements WC_Importer_Interface { return apply_filters( 'woocommerce_product_importer_parsed_data', $this->parsed_data, $this->get_raw_data() ); } + /** + * Get importer parameters. + * + * @return array + */ + public function get_params() { + return $this->params; + } + /** * Get file pointer position from the last read. *