default.php
1 year ago
generic.php
8 years ago
mappings.php
7 years ago
shopify.php
7 years ago
wordpress.php
8 years ago
default.php
120 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Default mappings |
| 4 | * |
| 5 | * @package WooCommerce\Admin\Importers |
| 6 | */ |
| 7 | |
| 8 | use Automattic\WooCommerce\Internal\CostOfGoodsSold\CostOfGoodsSoldController; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Importer current locale. |
| 16 | * |
| 17 | * @since 3.1.0 |
| 18 | * @return string |
| 19 | */ |
| 20 | function wc_importer_current_locale() { |
| 21 | $locale = get_locale(); |
| 22 | if ( function_exists( 'get_user_locale' ) ) { |
| 23 | $locale = get_user_locale(); |
| 24 | } |
| 25 | |
| 26 | return $locale; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Add English mapping placeholders when not using English as current language. |
| 31 | * |
| 32 | * @since 3.1.0 |
| 33 | * @param array $mappings Importer columns mappings. |
| 34 | * @return array |
| 35 | */ |
| 36 | function wc_importer_default_english_mappings( $mappings ) { |
| 37 | if ( 'en_US' === wc_importer_current_locale() && is_array( $mappings ) && count( $mappings ) > 0 ) { |
| 38 | return $mappings; |
| 39 | } |
| 40 | |
| 41 | $weight_unit = get_option( 'woocommerce_weight_unit' ); |
| 42 | $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
| 43 | $new_mappings = array( |
| 44 | 'ID' => 'id', |
| 45 | 'Type' => 'type', |
| 46 | 'SKU' => 'sku', |
| 47 | 'Name' => 'name', |
| 48 | 'Published' => 'published', |
| 49 | 'Is featured?' => 'featured', |
| 50 | 'Visibility in catalog' => 'catalog_visibility', |
| 51 | 'Short description' => 'short_description', |
| 52 | 'Description' => 'description', |
| 53 | 'Date sale price starts' => 'date_on_sale_from', |
| 54 | 'Date sale price ends' => 'date_on_sale_to', |
| 55 | 'Tax status' => 'tax_status', |
| 56 | 'Tax class' => 'tax_class', |
| 57 | 'In stock?' => 'stock_status', |
| 58 | 'Stock' => 'stock_quantity', |
| 59 | 'Backorders allowed?' => 'backorders', |
| 60 | 'Low stock amount' => 'low_stock_amount', |
| 61 | 'Sold individually?' => 'sold_individually', |
| 62 | sprintf( 'Weight (%s)', $weight_unit ) => 'weight', |
| 63 | sprintf( 'Length (%s)', $dimension_unit ) => 'length', |
| 64 | sprintf( 'Width (%s)', $dimension_unit ) => 'width', |
| 65 | sprintf( 'Height (%s)', $dimension_unit ) => 'height', |
| 66 | 'Allow customer reviews?' => 'reviews_allowed', |
| 67 | 'Purchase note' => 'purchase_note', |
| 68 | 'Sale price' => 'sale_price', |
| 69 | 'Regular price' => 'regular_price', |
| 70 | 'Categories' => 'category_ids', |
| 71 | 'Tags' => 'tag_ids', |
| 72 | 'Shipping class' => 'shipping_class_id', |
| 73 | 'Images' => 'images', |
| 74 | 'Download limit' => 'download_limit', |
| 75 | 'Download expiry days' => 'download_expiry', |
| 76 | 'Parent' => 'parent_id', |
| 77 | 'Upsells' => 'upsell_ids', |
| 78 | 'Cross-sells' => 'cross_sell_ids', |
| 79 | 'Grouped products' => 'grouped_products', |
| 80 | 'External URL' => 'product_url', |
| 81 | 'Button text' => 'button_text', |
| 82 | 'Position' => 'menu_order', |
| 83 | ); |
| 84 | |
| 85 | if ( wc_get_container()->get( CostOfGoodsSoldController::class )->feature_is_enabled() ) { |
| 86 | $new_mappings['Cost of goods'] = 'cogs_value'; |
| 87 | } |
| 88 | |
| 89 | return array_merge( $mappings, $new_mappings ); |
| 90 | } |
| 91 | add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'wc_importer_default_english_mappings', 100 ); |
| 92 | |
| 93 | /** |
| 94 | * Add English special mapping placeholders when not using English as current language. |
| 95 | * |
| 96 | * @since 3.1.0 |
| 97 | * @param array $mappings Importer columns mappings. |
| 98 | * @return array |
| 99 | */ |
| 100 | function wc_importer_default_special_english_mappings( $mappings ) { |
| 101 | if ( 'en_US' === wc_importer_current_locale() && is_array( $mappings ) && count( $mappings ) > 0 ) { |
| 102 | return $mappings; |
| 103 | } |
| 104 | |
| 105 | $new_mappings = array( |
| 106 | 'Attribute %d name' => 'attributes:name', |
| 107 | 'Attribute %d value(s)' => 'attributes:value', |
| 108 | 'Attribute %d visible' => 'attributes:visible', |
| 109 | 'Attribute %d global' => 'attributes:taxonomy', |
| 110 | 'Attribute %d default' => 'attributes:default', |
| 111 | 'Download %d ID' => 'downloads:id', |
| 112 | 'Download %d name' => 'downloads:name', |
| 113 | 'Download %d URL' => 'downloads:url', |
| 114 | 'Meta: %s' => 'meta:', |
| 115 | ); |
| 116 | |
| 117 | return array_merge( $mappings, $new_mappings ); |
| 118 | } |
| 119 | add_filter( 'woocommerce_csv_product_import_mapping_special_columns', 'wc_importer_default_special_english_mappings', 100 ); |
| 120 |