initial commit

This commit is contained in:
2021-12-10 12:03:04 +00:00
commit c46c7ddbf0
3643 changed files with 582794 additions and 0 deletions

View File

@ -0,0 +1,113 @@
<?php
/**
* Default mappings
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Importer current locale.
*
* @since 3.1.0
* @return string
*/
function wc_importer_current_locale() {
$locale = get_locale();
if ( function_exists( 'get_user_locale' ) ) {
$locale = get_user_locale();
}
return $locale;
}
/**
* Add English mapping placeholders when not using English as current language.
*
* @since 3.1.0
* @param array $mappings Importer columns mappings.
* @return array
*/
function wc_importer_default_english_mappings( $mappings ) {
if ( 'en_US' === wc_importer_current_locale() ) {
return $mappings;
}
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$new_mappings = array(
'ID' => 'id',
'Type' => 'type',
'SKU' => 'sku',
'Name' => 'name',
'Published' => 'published',
'Is featured?' => 'featured',
'Visibility in catalog' => 'catalog_visibility',
'Short description' => 'short_description',
'Description' => 'description',
'Date sale price starts' => 'date_on_sale_from',
'Date sale price ends' => 'date_on_sale_to',
'Tax status' => 'tax_status',
'Tax class' => 'tax_class',
'In stock?' => 'stock_status',
'Stock' => 'stock_quantity',
'Backorders allowed?' => 'backorders',
'Low stock amount' => 'low_stock_amount',
'Sold individually?' => 'sold_individually',
sprintf( 'Weight (%s)', $weight_unit ) => 'weight',
sprintf( 'Length (%s)', $dimension_unit ) => 'length',
sprintf( 'Width (%s)', $dimension_unit ) => 'width',
sprintf( 'Height (%s)', $dimension_unit ) => 'height',
'Allow customer reviews?' => 'reviews_allowed',
'Purchase note' => 'purchase_note',
'Sale price' => 'sale_price',
'Regular price' => 'regular_price',
'Categories' => 'category_ids',
'Tags' => 'tag_ids',
'Shipping class' => 'shipping_class_id',
'Images' => 'images',
'Download limit' => 'download_limit',
'Download expiry days' => 'download_expiry',
'Parent' => 'parent_id',
'Upsells' => 'upsell_ids',
'Cross-sells' => 'cross_sell_ids',
'Grouped products' => 'grouped_products',
'External URL' => 'product_url',
'Button text' => 'button_text',
'Position' => 'menu_order',
);
return array_merge( $mappings, $new_mappings );
}
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'wc_importer_default_english_mappings', 100 );
/**
* Add English special mapping placeholders when not using English as current language.
*
* @since 3.1.0
* @param array $mappings Importer columns mappings.
* @return array
*/
function wc_importer_default_special_english_mappings( $mappings ) {
if ( 'en_US' === wc_importer_current_locale() ) {
return $mappings;
}
$new_mappings = array(
'Attribute %d name' => 'attributes:name',
'Attribute %d value(s)' => 'attributes:value',
'Attribute %d visible' => 'attributes:visible',
'Attribute %d global' => 'attributes:taxonomy',
'Attribute %d default' => 'attributes:default',
'Download %d ID' => 'downloads:id',
'Download %d name' => 'downloads:name',
'Download %d URL' => 'downloads:url',
'Meta: %s' => 'meta:',
);
return array_merge( $mappings, $new_mappings );
}
add_filter( 'woocommerce_csv_product_import_mapping_special_columns', 'wc_importer_default_special_english_mappings', 100 );

View File

@ -0,0 +1,31 @@
<?php
/**
* Generic mappings
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Add generic mappings.
*
* @since 3.1.0
* @param array $mappings Importer columns mappings.
* @return array
*/
function wc_importer_generic_mappings( $mappings ) {
$generic_mappings = array(
__( 'Title', 'woocommerce' ) => 'name',
__( 'Product Title', 'woocommerce' ) => 'name',
__( 'Price', 'woocommerce' ) => 'regular_price',
__( 'Parent SKU', 'woocommerce' ) => 'parent_id',
__( 'Quantity', 'woocommerce' ) => 'stock_quantity',
__( 'Menu order', 'woocommerce' ) => 'menu_order',
);
return array_merge( $mappings, $generic_mappings );
}
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'wc_importer_generic_mappings' );

View File

@ -0,0 +1,15 @@
<?php
/**
* Load up extra automatic mappings for the CSV importer.
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require dirname( __FILE__ ) . '/default.php';
require dirname( __FILE__ ) . '/generic.php';
require dirname( __FILE__ ) . '/shopify.php';
require dirname( __FILE__ ) . '/wordpress.php';

View File

@ -0,0 +1,90 @@
<?php
/**
* Shopify mappings
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Add Shopify mappings.
*
* @since 3.7.0
* @param array $mappings Importer columns mappings.
* @param array $raw_headers Raw headers from CSV being imported.
* @return array
*/
function wc_importer_shopify_mappings( $mappings, $raw_headers ) {
// Only map if this is looks like a Shopify export.
if ( 0 !== count( array_diff( array( 'Title', 'Body (HTML)', 'Type', 'Variant SKU' ), $raw_headers ) ) ) {
return $mappings;
}
$shopify_mappings = array(
'Variant SKU' => 'sku',
'Title' => 'name',
'Body (HTML)' => 'description',
'Quantity' => 'stock_quantity',
'Variant Inventory Qty' => 'stock_quantity',
'Image Src' => 'images',
'Variant Image' => 'images',
'Variant SKU' => 'sku',
'Variant Price' => 'sale_price',
'Variant Compare At Price' => 'regular_price',
'Type' => 'category_ids',
'Tags' => 'tag_ids_spaces',
'Variant Grams' => 'weight',
'Variant Requires Shipping' => 'meta:shopify_requires_shipping',
'Variant Taxable' => 'tax_status',
);
return array_merge( $mappings, $shopify_mappings );
}
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'wc_importer_shopify_mappings', 10, 2 );
/**
* Add special wildcard Shopify mappings.
*
* @since 3.7.0
* @param array $mappings Importer columns mappings.
* @param array $raw_headers Raw headers from CSV being imported.
* @return array
*/
function wc_importer_shopify_special_mappings( $mappings, $raw_headers ) {
// Only map if this is looks like a Shopify export.
if ( 0 !== count( array_diff( array( 'Title', 'Body (HTML)', 'Type', 'Variant SKU' ), $raw_headers ) ) ) {
return $mappings;
}
$shopify_mappings = array(
'Option%d Name' => 'attributes:name',
'Option%d Value' => 'attributes:value',
);
return array_merge( $mappings, $shopify_mappings );
}
add_filter( 'woocommerce_csv_product_import_mapping_special_columns', 'wc_importer_shopify_special_mappings', 10, 2 );
/**
* Expand special Shopify columns to WC format.
*
* @since 3.7.0
* @param array $data Array of data.
* @return array Expanded data.
*/
function wc_importer_shopify_expand_data( $data ) {
if ( isset( $data['meta:shopify_requires_shipping'] ) ) {
$requires_shipping = wc_string_to_bool( $data['meta:shopify_requires_shipping'] );
if ( ! $requires_shipping ) {
if ( isset( $data['type'] ) ) {
$data['type'][] = 'virtual';
} else {
$data['type'] = array( 'virtual' );
}
}
unset( $data['meta:shopify_requires_shipping'] );
}
return $data;
}
add_filter( 'woocommerce_product_importer_pre_expand_data', 'wc_importer_shopify_expand_data' );

View File

@ -0,0 +1,31 @@
<?php
/**
* WordPress mappings
*
* @package WooCommerce\Admin\Importers
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Add mappings for WordPress tables.
*
* @since 3.1.0
* @param array $mappings Importer columns mappings.
* @return array
*/
function wc_importer_wordpress_mappings( $mappings ) {
$wp_mappings = array(
'post_id' => 'id',
'post_title' => 'name',
'post_content' => 'description',
'post_excerpt' => 'short_description',
'post_parent' => 'parent_id',
);
return array_merge( $mappings, $wp_mappings );
}
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'wc_importer_wordpress_mappings' );