/var/www/(Del)hsihk.com/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-importers.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
 * Setup importers for WC data.
 *
 * @author         WooThemes
 * @category     Admin
 * @package     WooCommerce/Admin
 * @version     2.1.0
 */

if ( ! defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly
}

if ( ! 
class_exists'WC_Admin_Importers' ) ) :

/**
 * WC_Admin_Importers Class
 */
class WC_Admin_Importers {

    
/**
     * Hook in tabs.
     */
    
public function __construct() {
        
add_action'admin_init', array( $this'register_importers' ) );
        
add_action'import_start', array( $this'post_importer_compatibility' ) );
    }

    
/**
     * Add menu items
     */
    
public function register_importers() {
        
register_importer'woocommerce_tax_rate_csv'__'WooCommerce Tax Rates (CSV)''woocommerce' ), __'Import <strong>tax rates</strong> to your store via a csv file.''woocommerce'), array( $this'tax_rates_importer' ) );
    }

    
/**
     * Add menu item
     */
    
public function tax_rates_importer() {
        
// Load Importer API
        
require_once ABSPATH 'wp-admin/includes/import.php';

        if ( ! 
class_exists'WP_Importer' ) ) {
            
$class_wp_importer ABSPATH 'wp-admin/includes/class-wp-importer.php';
            if ( 
file_exists$class_wp_importer ) )
                require 
$class_wp_importer;
        }

        
// includes
        
require 'importers/class-wc-tax-rate-importer.php';

        
// Dispatch
        
$importer = new WC_Tax_Rate_Importer();
        
$importer->dispatch();
    }

    
/**
     * When running the WP importer, ensure attributes exist.
     *
     * WordPress import should work - however, it fails to import custom product attribute taxonomies.
     * This code grabs the file before it is imported and ensures the taxonomies are created.
     *
     * @access public
     * @return void
     */
    
public function post_importer_compatibility() {
        global 
$wpdb;

        if ( empty( 
$_POST['import_id'] ) || ! class_exists'WXR_Parser' ) )
            return;

        
$id          = (int) $_POST['import_id'];
        
$file        get_attached_file$id );
        
$parser      = new WXR_Parser();
        
$import_data $parser->parse$file );

        if ( isset( 
$import_data['posts'] ) ) {
            
$posts $import_data['posts'];

            if ( 
$posts && sizeof$posts ) > ) foreach ( $posts as $post ) {

                if ( 
$post['post_type'] == 'product' ) {

                    if ( 
$post['terms'] && sizeof$post['terms'] ) > ) {

                        foreach ( 
$post['terms'] as $term ) {

                            
$domain $term['domain'];

                            if ( 
strstr$domain'pa_' ) ) {

                                
// Make sure it exists!
                                
if ( ! taxonomy_exists$domain ) ) {

                                    
$nicename strtolowersanitize_titlestr_replace'pa_'''$domain ) ) );

                                    
$exists_in_db $wpdb->get_var$wpdb->prepare"SELECT attribute_id FROM " $wpdb->prefix "woocommerce_attribute_taxonomies WHERE attribute_name = %s;"$nicename ) );

                                    
// Create the taxonomy
                                    
if ( ! $exists_in_db )
                                        
$wpdb->insert$wpdb->prefix "woocommerce_attribute_taxonomies", array( 'attribute_name' => $nicename'attribute_type' => 'select''attribute_orderby' => 'menu_order' ), array( '%s''%s''%s' ) );

                                    
// Register the taxonomy now so that the import works!
                                    
register_taxonomy$domain,
                                        
apply_filters'woocommerce_taxonomy_objects_' $domain, array('product') ),
                                        
apply_filters'woocommerce_taxonomy_args_' $domain, array(
                                            
'hierarchical' => true,
                                            
'show_ui' => false,
                                            
'query_var' => true,
                                            
'rewrite' => false,
                                        ) )
                                    );
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

endif;

return new 
WC_Admin_Importers();