html-csv-import-mapping.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Admin View: Importer - CSV mapping
  4. *
  5. * @package WooCommerce\Admin\Importers
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit;
  9. }
  10. ?>
  11. <form class="wc-progress-form-content woocommerce-importer" method="post" action="<?php echo esc_url( $this->get_next_step_link() ); ?>">
  12. <header>
  13. <h2><?php esc_html_e( 'Map CSV fields to products', 'woocommerce' ); ?></h2>
  14. <p><?php esc_html_e( 'Select fields from your CSV file to map against products fields, or to ignore during import.', 'woocommerce' ); ?></p>
  15. </header>
  16. <section class="wc-importer-mapping-table-wrapper">
  17. <table class="widefat wc-importer-mapping-table">
  18. <thead>
  19. <tr>
  20. <th><?php esc_html_e( 'Column name', 'woocommerce' ); ?></th>
  21. <th><?php esc_html_e( 'Map to field', 'woocommerce' ); ?></th>
  22. </tr>
  23. </thead>
  24. <tbody>
  25. <?php foreach ( $headers as $index => $name ) : ?>
  26. <?php $mapped_value = $mapped_items[ $index ]; ?>
  27. <tr>
  28. <td class="wc-importer-mapping-table-name">
  29. <?php echo esc_html( $name ); ?>
  30. <?php if ( ! empty( $sample[ $index ] ) ) : ?>
  31. <span class="description"><?php esc_html_e( 'Sample:', 'woocommerce' ); ?> <code><?php echo esc_html( $sample[ $index ] ); ?></code></span>
  32. <?php endif; ?>
  33. </td>
  34. <td class="wc-importer-mapping-table-field">
  35. <input type="hidden" name="map_from[<?php echo esc_attr( $index ); ?>]" value="<?php echo esc_attr( $name ); ?>" />
  36. <select name="map_to[<?php echo esc_attr( $index ); ?>]">
  37. <option value=""><?php esc_html_e( 'Do not import', 'woocommerce' ); ?></option>
  38. <option value="">--------------</option>
  39. <?php foreach ( $this->get_mapping_options( $mapped_value ) as $key => $value ) : ?>
  40. <?php if ( is_array( $value ) ) : ?>
  41. <optgroup label="<?php echo esc_attr( $value['name'] ); ?>">
  42. <?php foreach ( $value['options'] as $sub_key => $sub_value ) : ?>
  43. <option value="<?php echo esc_attr( $sub_key ); ?>" <?php selected( $mapped_value, $sub_key ); ?>><?php echo esc_html( $sub_value ); ?></option>
  44. <?php endforeach ?>
  45. </optgroup>
  46. <?php else : ?>
  47. <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $mapped_value, $key ); ?>><?php echo esc_html( $value ); ?></option>
  48. <?php endif; ?>
  49. <?php endforeach ?>
  50. </select>
  51. </td>
  52. </tr>
  53. <?php endforeach; ?>
  54. </tbody>
  55. </table>
  56. </section>
  57. <div class="wc-actions">
  58. <button type="submit" class="button button-primary button-next" value="<?php esc_attr_e( 'Run the importer', 'woocommerce' ); ?>" name="save_step"><?php esc_html_e( 'Run the importer', 'woocommerce' ); ?></button>
  59. <input type="hidden" name="file" value="<?php echo esc_attr( $this->file ); ?>" />
  60. <input type="hidden" name="delimiter" value="<?php echo esc_attr( $this->delimiter ); ?>" />
  61. <input type="hidden" name="update_existing" value="<?php echo (int) $this->update_existing; ?>" />
  62. <?php wp_nonce_field( 'woocommerce-csv-importer' ); ?>
  63. </div>
  64. </form>