marsmp
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Hi there,
we have mange to import custom taxonomy by using bellow code.
note:But we only able import single taxonomy not nested taxonomy is that any way anyone can helps out?we have found Reference code and modify it are below:-
https://gist.github.com/helgatheviking/114c8df50cabb7119b3c895b1d854533
/* Add Custom Taxonomy(Manufacture) in Product Function Start */
function custom_taxonomy() { $labels = array( 'name' => _x( 'Manufacture', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Manufacture', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Manufacture', 'text_domain' ), 'all_items' => __( 'All Items', 'text_domain' ), 'parent_item' => __( 'Parent Item', 'text_domain' ), 'parent_item_colon' => __( 'Parent Item:', 'text_domain' ), 'new_item_name' => __( 'New Item Name', 'text_domain' ), 'add_new_item' => __( 'Add New Item', 'text_domain' ), 'edit_item' => __( 'Edit Item', 'text_domain' ), 'update_item' => __( 'Update Item', 'text_domain' ), 'view_item' => __( 'View Item', 'text_domain' ), 'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ), 'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ), 'popular_items' => __( 'Popular Items', 'text_domain' ), 'search_items' => __( 'Search Items', 'text_domain' ), 'not_found' => __( 'Not Found', 'text_domain' ), 'no_terms' => __( 'No items', 'text_domain' ), 'items_list' => __( 'Items list', 'text_domain' ), 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy( 'manufacture', array( 'product' ), $args ); } add_action( 'init', 'custom_taxonomy', 0 );/* Add Custom Taxonomy(Manufacture) in Product Function End*/
/*********logic code for custom taxonomy************/
/** * Import shop section of the products from the CSV file */ /** * Register the 'Custom Column' column in the importer. * * @param array $options * @return array $options */ function kia_map_columns( $options ) { $options[ 'manufacture' ] = __( 'Manufacture', 'woocommerce' ); return $options; } add_filter( 'woocommerce_csv_product_import_mapping_options', 'kia_map_columns' ); /** * Add automatic mapping support for custom columns. * * @param array $columns * @return array $columns */ function kia_add_columns_to_mapping_screen( $columns ) { $columns[ __( 'Manufacture', 'woocommerce' ) ] = 'manufacture'; // Always add English mappings. $columns[ 'Manufacture' ] = 'manufacture'; return $columns; } add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'kia_add_columns_to_mapping_screen' ); /** * Set taxonomy. * * @param array $parsed_data * @return array */ function kia_set_taxonomy( $product, $data ) { if ( is_a( $product, 'WC_Product' ) ) { if( ! empty( $data [ 'manufacture' ] ) ) { wp_set_object_terms( $product->get_id(), (array) $data ['manufacture'], 'manufacture' ); } } return $product; } add_filter( 'woocommerce_product_import_inserted_product_object', 'kia_set_taxonomy', 10, 2 );/*********for custom brand taxonomy***********/
function brand_map_columns( $options ) { $options[ 'product_brand' ] = __( 'Product Brand', 'woocommerce' ); return $options; } add_filter( 'woocommerce_csv_product_import_mapping_options', 'brand_map_columns' ); function kia_add_brand_columns_to_mapping_screen( $columns ) { $columns[ __( 'Product Brand', 'woocommerce' ) ] = 'product_brand'; // Always add English mappings. $columns[ 'Product Brand' ] = 'product_brand'; return $columns; } add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'kia_add_brand_columns_to_mapping_screen' ); function brand_set_taxonomy( $product, $data ) { if ( is_a( $product, 'WC_Product' ) ) { if( ! empty( $data [ 'product_brand' ] ) ) { wp_set_object_terms( $product->get_id(), (array) $data ['product_brand'], 'product_brand' ); } } return $product; } add_filter( 'woocommerce_product_import_inserted_product_object', 'brand_set_taxonomy', 10, 2 );- This reply was modified 6 years, 12 months ago by marsmp.
Viewing 1 replies (of 1 total)