Created
April 27, 2021 11:14
-
-
Save DxDiagDx/1a4d2e832f29c299c0e7be0d0e4f14b6 to your computer and use it in GitHub Desktop.
Woo Import: добавить произвольное поле в стандартный импорт
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Register the 'Custom Column' column in the importer. | |
* | |
* @param array $options | |
* @return array $options | |
*/ | |
add_filter( 'woocommerce_csv_product_import_mapping_options', 'add_column_to_importer' ); | |
function add_column_to_importer( $options ) { | |
// column slug => column name | |
$options['_price_types_1'] = 'Оптовая цена'; return $options; | |
} | |
/** | |
* Add automatic mapping support for 'Custom Column'. | |
* This will automatically select the correct mapping for columns named 'Custom Column' or 'custom column'. | |
* | |
* @param array $columns | |
* @return array $columns | |
*/ | |
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'add_column_to_mapping_screen' ); | |
function add_column_to_mapping_screen( $columns ) { | |
// potential column name => column slug | |
$columns['Оптовая цена'] = '_price_types_1'; | |
$columns['оптовая цена'] = '_price_types_1'; | |
return $columns; | |
} | |
/** | |
* Process the data read from the CSV file. | |
* This just saves the value in meta data, but you can do anything you want here with the data. | |
* | |
* @param WC_Product $object - Product being imported or updated. | |
* @param array $data - CSV data read for the product. | |
* @return WC_Product $object | |
*/ | |
add_filter( 'woocommerce_product_import_pre_insert_product_object', 'process_import', 10, 2 ); | |
function process_import( $object, $data ) { | |
if ( ! empty( $data['_price_types_1'] ) ) { | |
$object->update_meta_data( '_price_types_1', $data['_price_types_1'] ); | |
} | |
return $object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment