Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Woo Import: добавить произвольное поле в стандартный импорт
/**
* 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