default.php 4.2 KB

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