From c08d3a356e70bd19f449a9bf7082d6d38247ed78 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 24 May 2017 03:42:15 -0300 Subject: [PATCH] Added support "Attribute %d Visible" --- .../class-wc-product-csv-importer-controller.php | 6 ++++-- includes/import/class-wc-product-csv-importer.php | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index 3b90b608826..0335a8f078d 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -438,6 +438,7 @@ class WC_Product_CSV_Importer_Controller { array( 'attributes:name' => __( 'Attribute %d Name', 'woocommerce' ), 'attributes:value' => __( 'Attribute %d Value(s)', 'woocommerce' ), + 'attributes:visible' => __( 'Attribute %d Visible', 'woocommerce' ), 'attributes:default' => __( 'Attribute %d Default', 'woocommerce' ), 'downloads:name' => __( 'Download %d Name', 'woocommerce' ), 'downloads:url' => __( 'Download %d URL', 'woocommerce' ), @@ -555,8 +556,9 @@ class WC_Product_CSV_Importer_Controller { 'attributes' => array( 'name' => __( 'Attributes', 'woocommerce' ), 'options' => array( - 'attributes:name' . $index => __( 'Attributes name', 'woocommerce' ), - 'attributes:value' . $index => __( 'Attributes value', 'woocommerce' ), + 'attributes:name' . $index => __( 'Attribute name', 'woocommerce' ), + 'attributes:value' . $index => __( 'Attribute value(s)', 'woocommerce' ), + 'attributes:visible' . $index => __( 'Attribute visibility', 'woocommerce' ), 'attributes:default' . $index => __( 'Default attribute', 'woocommerce' ), ), ), diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index f65c2e3fc67..13baa2b3df9 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -323,9 +323,10 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { * Match special column names. */ $regex_match_data_formatting = array( - '/attributes:value*/' => array( $this, 'parse_comma_field' ), - '/downloads:url*/' => 'esc_url', - '/meta:*/' => 'wp_kses_post', // Allow some HTML in meta fields. + '/attributes:value*/' => array( $this, 'parse_comma_field' ), + '/attributes:visible*/' => array( $this, 'parse_bool_field' ), + '/downloads:url*/' => 'esc_url', + '/meta:*/' => 'wp_kses_post', // Allow some HTML in meta fields. ); $callbacks = array(); @@ -419,6 +420,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { unset( $data[ $key ] ); } + if ( $this->starts_with( $key, 'attributes:visible' ) ) { + if ( ! empty( $value ) ) { + $data['attributes'][ str_replace( 'attributes:visible', '', $key ) ]['visible'] = $value; + } + + unset( $data[ $key ] ); + } // Default attributes if ( $this->starts_with( $key, 'attributes:default' ) ) {