YITH WooCommerce Ajax Search - Version 1.5.1

Version Description

  • Released: Mar 28, 2017 = New: Support to WooCommerce 3.0 RC 2 Update: Plugin Core
Download this release

Release Info

Developer yithemes
Plugin Icon 128x128 YITH WooCommerce Ajax Search
Version 1.5.1
Comparing to
See all releases

Code changes from version 1.5.0 to 1.5.1

README.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: yithemes
4
  Tags: woocommerce search by sku, woocommerce search results, woocommerce search shortcode, woocommerce search page, woocommerce search form, woocommerce search filter, woocommerce search products, woocommerce search content, woocommerce search autocomplete, woocommerce advanced search, woocommerce search category, woocommerce search product attributes, woocommerce search by tag, woocommerce search by brand, woocommerce predictive, woocommerce live search, woocommerce single product search, woocommerce site search, woocommerce search tex, tajax, search, woocommerce, products, themes, yit, e-commerce, shop, yith, ajax search, instant search, premium, yithemes, autocomplete, autosuggest, better search, category search, custom search, highlight terms, Live Search, Predictive Search, product search, relevant search, search highlight, search product, suggest, typeahead, WooCommerce Plugin, woocommerce product search, woocommerce search, wordpress ecommerce
5
  Requires at least: 4.0.0
6
  Tested up to: 4.6.1
7
- Stable tag: 1.5.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -138,6 +138,10 @@ If you have created your own language pack for YITH WooCommerce Ajax Search, or
138
  2. YITH WooCommerce Ajax Search in operation displaying WooCommerce search results
139
 
140
  == Changelog ==
 
 
 
 
141
  = 1.5.0 - Released: Mar 06, 2017 =
142
  New: Support to WooCommerce 2.7 RC 1
143
  Update: Plugin Core
4
  Tags: woocommerce search by sku, woocommerce search results, woocommerce search shortcode, woocommerce search page, woocommerce search form, woocommerce search filter, woocommerce search products, woocommerce search content, woocommerce search autocomplete, woocommerce advanced search, woocommerce search category, woocommerce search product attributes, woocommerce search by tag, woocommerce search by brand, woocommerce predictive, woocommerce live search, woocommerce single product search, woocommerce site search, woocommerce search tex, tajax, search, woocommerce, products, themes, yit, e-commerce, shop, yith, ajax search, instant search, premium, yithemes, autocomplete, autosuggest, better search, category search, custom search, highlight terms, Live Search, Predictive Search, product search, relevant search, search highlight, search product, suggest, typeahead, WooCommerce Plugin, woocommerce product search, woocommerce search, wordpress ecommerce
5
  Requires at least: 4.0.0
6
  Tested up to: 4.6.1
7
+ Stable tag: 1.5.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
138
  2. YITH WooCommerce Ajax Search in operation displaying WooCommerce search results
139
 
140
  == Changelog ==
141
+ = 1.5.1 - Released: Mar 28, 2017 =
142
+ New: Support to WooCommerce 3.0 RC 2
143
+ Update: Plugin Core
144
+
145
  = 1.5.0 - Released: Mar 06, 2017 =
146
  New: Support to WooCommerce 2.7 RC 1
147
  Update: Plugin Core
init.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: YITH WooCommerce Ajax Search
4
  * Plugin URI: http://yithemes.com/
5
  * Description: YITH WooCommerce Ajax Search allows your users to search products in real time.
6
- * Version: 1.5.0
7
  * Author: YITHEMES
8
  * Author URI: http://yithemes.com/
9
  * Text Domain: yith-woocommerce-ajax-search
@@ -65,7 +65,7 @@ register_activation_hook( __FILE__, 'yith_plugin_registration_hook' );
65
  if ( defined( 'YITH_WCAS_VERSION' ) ){
66
  return;
67
  }else{
68
- define( 'YITH_WCAS_VERSION', '1.5.0' );
69
  }
70
 
71
  if ( ! defined( 'YITH_WCAS_FREE_INIT' ) ) {
3
  * Plugin Name: YITH WooCommerce Ajax Search
4
  * Plugin URI: http://yithemes.com/
5
  * Description: YITH WooCommerce Ajax Search allows your users to search products in real time.
6
+ * Version: 1.5.1
7
  * Author: YITHEMES
8
  * Author URI: http://yithemes.com/
9
  * Text Domain: yith-woocommerce-ajax-search
65
  if ( defined( 'YITH_WCAS_VERSION' ) ){
66
  return;
67
  }else{
68
+ define( 'YITH_WCAS_VERSION', '1.5.1' );
69
  }
70
 
71
  if ( ! defined( 'YITH_WCAS_FREE_INIT' ) ) {
plugin-fw/init.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Framework Name: YIT Plugin Framework
4
- * Version: 2.9.51
5
  * Author: Yithemes
6
  * Text Domain: yith-plugin-fw
7
  * Domain Path: /languages/
1
  <?php
2
  /**
3
  * Framework Name: YIT Plugin Framework
4
+ * Version: 2.9.59
5
  * Author: Yithemes
6
  * Text Domain: yith-plugin-fw
7
  * Domain Path: /languages/
plugin-fw/lib/yit-upgrade.php CHANGED
@@ -33,7 +33,7 @@ if ( ! class_exists( 'YIT_Upgrade' ) ) {
33
  /**
34
  * @var string api server url
35
  */
36
- protected $_package_url = 'http://www.yithemes.com';
37
 
38
  /**
39
  * @var array The registered plugins
33
  /**
34
  * @var string api server url
35
  */
36
+ protected $_package_url = 'https://yithemes.com';
37
 
38
  /**
39
  * @var array The registered plugins
plugin-fw/licence/lib/yit-licence.php CHANGED
@@ -48,7 +48,7 @@ if ( ! class_exists( 'YIT_Licence' ) ) {
48
  * @var string The yithemes api uri
49
  * @since 1.0
50
  */
51
- protected $_api_uri = 'http://yithemes.com';
52
 
53
  /**
54
  * @var string The yithemes api uri query args
@@ -692,7 +692,7 @@ if ( ! class_exists( 'YIT_Licence' ) ) {
692
  * @author Andrea Grillo <andrea.grillo@yithemes.com>
693
  */
694
  public function display_product_name( $product_name ){
695
- return str_replace( array( 'for WooCommerce', 'YITH', 'WooCommerce', 'Premium', 'Theme' ), '', $product_name );
696
  }
697
 
698
  public function get_number_of_membership_products(){
48
  * @var string The yithemes api uri
49
  * @since 1.0
50
  */
51
+ protected $_api_uri = 'https://yithemes.com';
52
 
53
  /**
54
  * @var string The yithemes api uri query args
692
  * @author Andrea Grillo <andrea.grillo@yithemes.com>
693
  */
694
  public function display_product_name( $product_name ){
695
+ return str_replace( array( 'for WooCommerce', 'YITH', 'WooCommerce', 'Premium', 'Theme', 'WordPress' ), '', $product_name );
696
  }
697
 
698
  public function get_number_of_membership_products(){
plugin-fw/licence/lib/yit-plugin-licence.php CHANGED
@@ -71,9 +71,9 @@ if ( !class_exists( 'YIT_Plugin_Licence' ) ) {
71
  );
72
 
73
  add_action( 'admin_menu', array( $this, 'add_submenu_page' ), 99 );
74
- add_action( "wp_ajax_activate-{$this->_product_type}", array( $this, 'activate' ) );
75
- add_action( "wp_ajax_deactivate-{$this->_product_type}", array( $this, 'deactivate' ) );
76
- add_action( "wp_ajax_update_licence_information-{$this->_product_type}", array( $this, 'update_licence_information' ) );
77
  add_action( 'yit_licence_after_check', array( $this, 'licence_after_check' ) );
78
  }
79
 
71
  );
72
 
73
  add_action( 'admin_menu', array( $this, 'add_submenu_page' ), 99 );
74
+ add_action( "wp_ajax_yith_activate-{$this->_product_type}", array( $this, 'activate' ) );
75
+ add_action( "wp_ajax_yith_deactivate-{$this->_product_type}", array( $this, 'deactivate' ) );
76
+ add_action( "wp_ajax_yith_update_licence_information-{$this->_product_type}", array( $this, 'update_licence_information' ) );
77
  add_action( 'yit_licence_after_check', array( $this, 'licence_after_check' ) );
78
  }
79
 
plugin-fw/licence/lib/yit-theme-licence.php CHANGED
@@ -73,9 +73,9 @@ if ( !class_exists( 'YIT_Theme_Licence' ) ) {
73
  );
74
 
75
  add_action( 'admin_menu', array( $this, 'add_submenu_page' ), 99 );
76
- add_action( "wp_ajax_activate-{$this->_product_type}", array( $this, 'activate' ) );
77
- add_action( "wp_ajax_deactivate-{$this->_product_type}", array( $this, 'deactivate' ) );
78
- add_action( "wp_ajax_update_licence_information-{$this->_product_type}", array( $this, 'update_licence_information' ) );
79
  }
80
 
81
  /**
73
  );
74
 
75
  add_action( 'admin_menu', array( $this, 'add_submenu_page' ), 99 );
76
+ add_action( "wp_ajax_yith_activate-{$this->_product_type}", array( $this, 'activate' ) );
77
+ add_action( "wp_ajax_yith_deactivate-{$this->_product_type}", array( $this, 'deactivate' ) );
78
+ add_action( "wp_ajax_yith_update_licence_information-{$this->_product_type}", array( $this, 'update_licence_information' ) );
79
  }
80
 
81
  /**
plugin-fw/licence/templates/panel/activation/activation-panel.php CHANGED
@@ -25,7 +25,7 @@ $num_members_products_activate = $this->get_number_of_membership_products();
25
  <div class="licence-check-section">
26
  <form method="post" id="licence-check-update" action="<?php echo admin_url( 'admin-ajax.php' ) ?>">
27
  <span class="licence-label" style="display: block;"><?php _e( 'Have you updated your licenses? Have you asked for an extension? Update information concerning your products.', 'yith-plugin-fw' ); ?></span>
28
- <input type="hidden" name="action" value="update_licence_information-<?php echo $this->get_product_type(); ?>" />
29
  <input type="submit" name="submit" value="<?php _e( 'Update license information', 'yith-plugin-fw' ) ?>" class="button-licence licence-check" />
30
  <div class="spinner"></div>
31
  </form>
@@ -61,7 +61,7 @@ $num_members_products_activate = $this->get_number_of_membership_products();
61
  <input type="submit" name="submit" value="<?php _e( 'Activate', 'yith-plugin-fw' )?>" class="button-licence licence-activation" data-formid="<?php echo $info['product_id'] ?>"/>
62
  </td>
63
  </tr>
64
- <input type="hidden" name="action" value="activate-<?php echo $this->get_product_type(); ?>" />
65
  <input type="hidden" name="product_init" value="<?php echo $init ?>" />
66
  </tbody>
67
  </table>
@@ -138,7 +138,7 @@ $num_members_products_activate = $this->get_number_of_membership_products();
138
  data-licence-email="<?php echo $info['licence']['email'] ?>"
139
  data-licence-key="<?php echo $info['licence']['licence_key'] ?>"
140
  data-product-init="<?php echo $init ?>"
141
- data-action="deactivate-<?php echo $this->get_product_type(); ?>">
142
  <?php _e( 'Deactivate', 'yith-plugin-fw' ) ?>
143
  </a>
144
 
25
  <div class="licence-check-section">
26
  <form method="post" id="licence-check-update" action="<?php echo admin_url( 'admin-ajax.php' ) ?>">
27
  <span class="licence-label" style="display: block;"><?php _e( 'Have you updated your licenses? Have you asked for an extension? Update information concerning your products.', 'yith-plugin-fw' ); ?></span>
28
+ <input type="hidden" name="action" value="yith_update_licence_information-<?php echo $this->get_product_type(); ?>" />
29
  <input type="submit" name="submit" value="<?php _e( 'Update license information', 'yith-plugin-fw' ) ?>" class="button-licence licence-check" />
30
  <div class="spinner"></div>
31
  </form>
61
  <input type="submit" name="submit" value="<?php _e( 'Activate', 'yith-plugin-fw' )?>" class="button-licence licence-activation" data-formid="<?php echo $info['product_id'] ?>"/>
62
  </td>
63
  </tr>
64
+ <input type="hidden" name="action" value="yith_activate-<?php echo $this->get_product_type(); ?>" />
65
  <input type="hidden" name="product_init" value="<?php echo $init ?>" />
66
  </tbody>
67
  </table>
138
  data-licence-email="<?php echo $info['licence']['email'] ?>"
139
  data-licence-key="<?php echo $info['licence']['licence_key'] ?>"
140
  data-product-init="<?php echo $init ?>"
141
+ data-action="yith_deactivate-<?php echo $this->get_product_type(); ?>">
142
  <?php _e( 'Deactivate', 'yith-plugin-fw' ) ?>
143
  </a>
144
 
plugin-fw/yit-plugin.php CHANGED
@@ -42,12 +42,20 @@ load_textdomain( 'yith-plugin-fw', get_template_directory() . '/core/plugin-fw/y
42
  // ...or from plugin folder
43
  || load_textdomain( 'yith-plugin-fw', dirname(__FILE__) . '/languages/yith-plugin-fw-' . apply_filters( 'plugin_locale', get_locale(), 'yith-plugin-fw' ) . '.mo' );
44
 
45
- if( apply_filters( 'yit_fw_wc_update_message_hook', true ) || ( function_exists( 'WC' ) && ! version_compare( WC()->version, '2.7', '>=' ) ) ){
 
 
 
 
 
 
46
  add_action( 'admin_notices', 'yit_fw_wc_update_message', 15 );
 
47
 
48
  if( ! function_exists( 'yit_fw_wc_update_message' ) ){
49
- function yit_fw_wc_update_message(){ ?>
50
- <div class="notice notice-error is-dismissible">
 
51
  <?php $message = 'the new WooCommerce version 2.7 will be soon released. <strong>Before</strong> proceeding with the update, please verify the plugins you are using are already compatible. You can check the compatibility status of YITH products'; ?>
52
  <?php $url = 'https://support.yithemes.com/hc/en-us/articles/215945378-Theme-and-Plugin-compatibility-with-WordPress-and-WooCommerce'; ?>
53
  <p><?php printf( '<strong>%s</strong> - %s <a href="%s" target="_blank">HERE</a>.', 'Please note', $message, $url ); ?></p>
@@ -55,4 +63,20 @@ if( apply_filters( 'yit_fw_wc_update_message_hook', true ) || ( function_exists(
55
  <?php
56
  }
57
  }
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  // ...or from plugin folder
43
  || load_textdomain( 'yith-plugin-fw', dirname(__FILE__) . '/languages/yith-plugin-fw-' . apply_filters( 'plugin_locale', get_locale(), 'yith-plugin-fw' ) . '.mo' );
44
 
45
+ /* === WooCommerce Update Message === */
46
+
47
+ /*if( apply_filters( 'yit_fw_wc_update_message_hook', true )
48
+ &&
49
+ ( function_exists( 'WC' ) && ! version_compare( WC()->version, '2.7', '>=' ) )
50
+ && ! isset( $_COOKIE['yith_wc_2_7_notice'] )
51
+ ){
52
  add_action( 'admin_notices', 'yit_fw_wc_update_message', 15 );
53
+ add_action( 'admin_enqueue_scripts', 'yit_plugin_fw_dismissable_notice', 20 );
54
 
55
  if( ! function_exists( 'yit_fw_wc_update_message' ) ){
56
+ function yit_fw_wc_update_message(){
57
+ ?>
58
+ <div id="yith-notice-is-dismissable" class="yith-wc-update-message notice notice-error is-dismissible">
59
  <?php $message = 'the new WooCommerce version 2.7 will be soon released. <strong>Before</strong> proceeding with the update, please verify the plugins you are using are already compatible. You can check the compatibility status of YITH products'; ?>
60
  <?php $url = 'https://support.yithemes.com/hc/en-us/articles/215945378-Theme-and-Plugin-compatibility-with-WordPress-and-WooCommerce'; ?>
61
  <p><?php printf( '<strong>%s</strong> - %s <a href="%s" target="_blank">HERE</a>.', 'Please note', $message, $url ); ?></p>
63
  <?php
64
  }
65
  }
66
+
67
+ if( ! function_exists( 'yit_plugin_fw_dismissable_notice' ) ){
68
+ function yit_plugin_fw_dismissable_notice(){
69
+ $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/';
70
+ wp_enqueue_script( 'jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie.min.js', array( 'jquery' ), '1.4.1', true);
71
+ $js = "jQuery( document ).ready( function(){
72
+ jQuery( '#yith-notice-is-dismissable' ).find('.notice-dismiss').on( 'click', function(){
73
+ jQuery.cookie('yith_wc_2_7_notice', 'dismiss', { path: '/' });
74
+ } );
75
+ } ); ";
76
+
77
+ wp_add_inline_script( 'jquery-cookie', $js );
78
+ }
79
+ }
80
+ }*/
81
+
82
+ /* ========================== */
plugin-fw/yit-woocommerce-compatibility.php CHANGED
@@ -8,609 +8,575 @@
8
  * http://www.gnu.org/licenses/gpl-3.0.txt
9
  */
10
 
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit;
13
  } // Exit if accessed directly
14
 
15
- if ( ! function_exists( 'WC' ) ) {
16
- return;
17
  }
18
 
19
  $changed_objects = array();
20
 
21
- if ( ! function_exists( 'yit_get_prop' ) ) {
22
- /**
23
- *
24
- */
25
- function yit_get_prop( $object, $key, $single = true, $context = 'view' ) {
26
-
27
- $prop_map = yit_return_new_attribute_map();
28
- $is_wc_data = $object instanceof WC_Data;
29
-
30
- if ( $is_wc_data ) {
31
- $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
32
-
33
- if ( ( $getter = "get{$key}" ) && method_exists( $object, $getter ) ) {
34
- return $object->$getter( $context );
35
- } elseif ( ( $getter = "get_{$key}" ) && method_exists( $object, $getter ) ) {
36
- return $object->$getter( $context );
37
- } else {
38
- return $object->get_meta( $key, $single );
39
- }
40
- } else {
41
- $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
42
-
43
- if ( isset( $object->$key ) ) {
44
- return $object->$key;
45
- } elseif ( yit_wc_check_post_columns( $key ) ) {
46
- return $object->post->$key;
47
- } else {
48
- $getter = 'get_user_meta';
49
- ! $object instanceof WC_Customer && $getter = 'get_post_meta';
50
-
51
- $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id;
52
-
53
- return $getter( $object_id, $key, true );
54
- }
55
- }
56
- }
57
  }
58
 
59
- if ( ! function_exists( 'yit_set_prop' ) ) {
60
- /**
61
- *
62
- */
63
- function yit_set_prop( $object, $arg1, $arg2 = false ) {
64
-
65
- if ( ! is_array( $arg1 ) ) {
66
- $arg1 = array(
67
- $arg1 => $arg2
68
- );
69
- }
70
-
71
- $prop_map = yit_return_new_attribute_map();
72
- $is_wc_data = $object instanceof WC_Data;
73
-
74
- foreach ( $arg1 as $key => $value ) {
75
- if ( $is_wc_data ) {
76
- $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
77
-
78
- if ( ( $setter = "set{$key}" ) && method_exists( $object, $setter ) ) {
79
- $object->$setter( $value );
80
- } elseif ( ( $setter = "set_{$key}" ) && method_exists( $object, $setter ) ) {
81
- $object->$setter( $value );
82
- } else {
83
- $object->update_meta_data( $key, $value );
84
- }
85
- } else {
86
- $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
87
- ( strpos( $key, '_' ) === 0 ) && $key = substr( $key, 1 );
88
-
89
- if ( yit_wc_check_post_columns( $key ) ) {
90
- $object->post->$key = $value;
91
- } else {
92
- $object->$key = $value;
93
- }
94
- }
95
- }
96
- }
97
  }
98
 
99
- if ( ! function_exists( 'yit_save_prop' ) ) {
100
- /**
101
- *
102
- */
103
- function yit_save_prop( $object, $arg1, $arg2 = false, $force_update = false ) {
104
- if ( ! is_array( $arg1 ) ) {
105
- $arg1 = array(
106
- $arg1 => $arg2
107
- );
108
- }
109
 
110
- $is_wc_data = $object instanceof WC_Data;
111
 
112
- foreach ( $arg1 as $key => $value ) {
113
- yit_set_prop( $object, $key, $value );
114
 
115
- if ( $is_wc_data ) {
116
- if( $force_update ){
117
  $object->save();
118
- }
119
- else {
120
  yit_store_changes( $object, $key, $value );
121
  }
122
- } else {
123
- if ( yit_wc_check_post_columns( $key ) ) {
124
- yit_store_changes( $object->post, $key, $value );
125
- } else {
126
- $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id;
127
-
128
- update_post_meta( $object_id, $key, $value );
129
- }
130
- }
131
- }
132
- }
133
- }
134
 
135
- if ( ! function_exists( 'yit_delete_prop' ) ) {
136
- /**
137
- *
138
- */
139
- function yit_delete_prop( $object, $key, $value = '' ) {
140
- $prop_map = yit_return_new_attribute_map();
141
- $is_wc_data = $object instanceof WC_Data;
142
-
143
- if ( $is_wc_data ) {
144
- $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
145
-
146
- if ( ( $setter = "set{$key}" ) && ( $getter = "get{$key}" ) && method_exists( $object, $setter ) && ( ! $value || $object->$getter == $value ) ) {
147
- $object->$setter( '' );
148
- } elseif ( ( $setter = "set_{$key}" ) && ( $getter = "get_{$key}" ) && method_exists( $object, $setter ) && ( ! $value || $object->$getter == $value ) ) {
149
- $object->$setter( '' );
150
- } elseif ( ( ! $value || $object->get_meta( $key ) == $value ) ) {
151
- $object->delete_meta_data( $key, $value );
152
- }
153
-
154
- yit_store_changes( $object );
155
- } else {
156
- if ( yit_wc_check_post_columns( $key ) && ( ! $value || $object->post->$key == $value ) ) {
157
- yit_store_changes( $object->post, $key, '' );
158
- } else {
159
- $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id;
160
-
161
- delete_post_meta( $object_id, $key, $value );
162
- }
163
- }
164
- }
165
  }
166
 
167
- if ( ! function_exists( 'yit_return_new_attribute_map' ) ) {
168
- function yit_return_new_attribute_map() {
169
- return array(
170
- 'post_parent' => 'parent_id',
171
- 'post_title' => 'name',
172
- 'post_status' => 'status',
173
- 'post_content' => 'description',
174
- /* Orders */
175
- 'paid_date' => 'date_paid',
176
- '_paid_date' => '_date_paid',
177
- 'completed_date' => 'date_completed',
178
- '_completed_date' => '_date_completed',
179
- '_order_date' => '_date_created',
180
- 'order_date' => 'date_created',
181
- 'order_total' => 'total',
182
- /* Products */
183
- 'visibility' => 'catalog_visibility',
184
- '_visibility' => '_catalog_visibility',
185
- 'sale_price_dates_from' => 'date_on_sale_from',
186
- '_sale_price_dates_from' => '_date_on_sale_from',
187
- 'sale_price_dates_to' => 'date_on_sale_to',
188
- '_sale_price_dates_to' => '_date_on_sale_to',
189
- );
190
- }
 
 
 
 
 
 
191
  }
192
 
193
- if ( ! function_exists( 'yit_store_changes' ) ) {
194
- function yit_store_changes( $object, $key = false, $value = false ) {
195
- global $changed_objects;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
- $is_wc_data = $object instanceof WC_Data;
 
 
198
 
199
- if ( $is_wc_data ) {
200
- /**
201
- * @var $object \WC_Data
202
- */
203
- $object_reference = $object->get_id();
204
 
205
- $cache_type = is_a( $object, 'WC_Product' ) ? 'product' : 'order';
206
- $cache_key = $cache_type . '-' . $object_reference;
207
- $cache_group = $cache_type . 's';
 
 
208
 
209
- $changed_objects[ $object_reference ]['object'] = $object;
210
- $changed_objects[ $object_reference ]['changes'][ $key ] = $value;
 
211
 
 
 
212
 
213
- wp_cache_set( $cache_key, $object, $cache_group );
214
- } else {
215
- $changed_objects[ $object->ID ][ $key ] = $value;
216
- }
217
- }
218
- }
219
 
220
- if ( ! function_exists( 'yit_send_changes_to_db' ) ) {
221
- function yit_send_changes_to_db() {
222
- global $changed_objects;
223
-
224
- if ( ! empty( $changed_objects ) ) {
225
- foreach ( $changed_objects as $id => $data ) {
226
- if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
227
- /**
228
- * @var $object \WC_Data
229
- */
230
- $object = is_a( $data['object'], 'WC_Product' ) ? wc_get_product( $id ) : wc_get_order( $id );
231
-
232
- yit_set_prop( $object, $data['changes'] );
233
- $object->save();
234
- } else {
235
- $data['ID'] = $id;
236
- wp_update_post( $data );
237
- }
238
- }
239
- }
240
- }
241
  }
242
 
243
- if ( ! function_exists( 'yit_get_orders' ) ) {
244
- /**
245
- *
246
- */
247
- function yit_get_orders( $args ) {
248
- if ( version_compare( WC()->version, '2.6', '<' ) ) {
249
- $args['fields'] = 'objects';
250
- $posts = get_posts( $args );
251
-
252
- return array_map( 'wc_get_order', $posts );
253
- } else {
254
- return wc_get_orders( $args );
255
- }
256
- }
257
- }
258
 
259
- if ( ! function_exists( 'yit_get_products' ) ) {
260
- /**
261
- *
262
- */
263
- function yit_get_products( $args ) {
264
- if ( version_compare( WC()->version, '2.6', '<' ) ) {
265
- $args['fields'] = 'objects';
266
- $posts = get_posts( $args );
267
-
268
- return array_map( 'wc_get_product', $posts );
269
- } else {
270
- return wc_get_products( $args );
271
- }
272
- }
273
- }
274
 
275
- if ( ! function_exists( 'yit_update_product_stock' ) ) {
276
- /**
277
- *
278
- */
279
- function yit_update_product_stock( $product, $stock_quantity = 1, $operation = 'set' ) {
280
- if ( function_exists( 'wc_update_product_stock' ) ) {
281
- $stock = wc_update_product_stock( $product, $stock_quantity, $operation );
282
- } else {
283
- switch ( $operation ) {
284
- case 'increase':
285
- $stock = $product->increase_stock( $stock_quantity );
286
- break;
287
- case 'decrease':
288
- $stock = $product->reduce_stock( $stock_quantity );
289
- break;
290
- case 'set':
291
- default:
292
- $stock = $product->set_stock( $stock_quantity );
293
- break;
294
- }
295
- }
296
-
297
- return $stock;
298
- }
299
  }
300
 
301
- if ( ! function_exists( 'yit_wc_deprecated_filters' ) ) {
302
- /**
303
- *
304
- */
305
- function yit_wc_deprecated_filters() {
306
- return apply_filters( 'yit_wc_deprecated_filters', array(
307
- 'woocommerce_email_order_schema_markup' => 'woocommerce_structured_data_order',
308
- 'woocommerce_product_width' => 'woocommerce_product_get_width',
309
- 'woocommerce_product_height' => 'woocommerce_product_get_height',
310
- 'woocommerce_product_length' => 'woocommerce_product_get_length',
311
- 'woocommerce_product_weight' => 'woocommerce_product_get_weight',
312
- 'woocommerce_get_sku' => 'woocommerce_product_get_sku',
313
- 'woocommerce_get_price' => 'woocommerce_product_get_price',
314
- 'woocommerce_get_regular_price' => 'woocommerce_product_get_regular_price',
315
- 'woocommerce_get_sale_price' => 'woocommerce_product_get_sale_price',
316
- 'woocommerce_product_tax_class' => 'woocommerce_product_get_tax_class',
317
- 'woocommerce_get_stock_quantity' => 'woocommerce_product_get_stock_quantity',
318
- 'woocommerce_get_product_attributes' => 'woocommerce_product_get_attributes',
319
- 'woocommerce_product_gallery_attachment_ids' => 'woocommerce_product_get_gallery_image_ids',
320
- 'woocommerce_product_review_count' => 'woocommerce_product_get_review_count',
321
- 'woocommerce_product_files' => 'woocommerce_product_get_downloads',
322
- 'woocommerce_get_currency' => 'woocommerce_order_get_currency',
323
- 'woocommerce_order_amount_discount_total' => 'woocommerce_order_get_discount_total',
324
- 'woocommerce_order_amount_discount_tax' => 'woocommerce_order_get_discount_tax',
325
- 'woocommerce_order_amount_shipping_total' => 'woocommerce_order_get_shipping_total',
326
- 'woocommerce_order_amount_shipping_tax' => 'woocommerce_order_get_shipping_tax',
327
- 'woocommerce_order_amount_cart_tax' => 'woocommerce_order_get_cart_tax',
328
- 'woocommerce_order_amount_total' => 'woocommerce_order_get_total',
329
- 'woocommerce_order_amount_total_tax' => 'woocommerce_order_get_total_tax',
330
- 'woocommerce_order_amount_total_discount' => 'woocommerce_order_get_total_discount',
331
- 'woocommerce_order_amount_subtotal' => 'woocommerce_order_get_subtotal',
332
- 'woocommerce_order_tax_totals' => 'woocommerce_order_get_tax_totals',
333
- 'woocommerce_refund_amount' => 'woocommerce_get_order_refund_get_amount',
334
- 'woocommerce_refund_reason' => 'woocommerce_get_order_refund_get_reason',
335
- 'default_checkout_country' => 'default_checkout_billing_country',
336
- 'default_checkout_state' => 'default_checkout_billing_state',
337
- 'default_checkout_postcode' => 'default_checkout_billing_postcode',
338
- 'woocommerce_add_order_item_meta' => 'woocommerce_new_order_item',
339
-
340
- ) );
341
- }
342
  }
343
 
344
- if ( ! function_exists( 'yit_fix_wc_deprecated_filters' ) ) {
345
- /**
346
- *
347
- */
348
- function yit_fix_wc_deprecated_filters() {
349
-
350
- if ( ! version_compare( WC()->version, '2.7.0', '<' ) ) {
351
- return;
352
- }
353
-
354
- $deprecated_filters = yit_wc_deprecated_filters();
355
- foreach ( $deprecated_filters as $old => $new ) {
356
- add_filter( $old, 'yit_wc_deprecated_filter_mapping', 10, 100 );
357
- }
358
- }
359
  }
360
 
361
- if ( ! function_exists( 'yit_wc_deprecated_filter_mapping' ) ) {
362
- /**
363
- *
364
- */
365
- function yit_wc_deprecated_filter_mapping() {
366
- $deprecated_filters = yit_wc_deprecated_filters();
367
-
368
- $filter = current_filter();
369
- $args = func_get_args();
370
- $data = $args[0];
371
-
372
-
373
- if ( isset( $deprecated_filters[ $filter ] ) ) {
374
- if ( has_filter( $deprecated_filters[ $filter ] ) ) {
375
- $data = apply_filters_ref_array( $deprecated_filters[ $filter ], $args );
376
- }
377
- }
 
 
 
 
378
 
379
- return $data;
380
- }
381
  }
382
 
383
- if ( ! function_exists( 'yit_wc_check_post_columns' ) ) {
384
- /**
385
- *
386
- */
387
- function yit_wc_check_post_columns( $key ) {
388
- $columns = array(
389
- 'post_author',
390
- 'post_date',
391
- 'post_date_gmt',
392
- 'post_content',
393
- 'post_title',
394
- 'post_excerpt',
395
- 'post_status',
396
- 'comment_status',
397
- 'ping_status',
398
- 'post_password',
399
- 'post_name',
400
- 'to_ping',
401
- 'pinged',
402
- 'post_modified',
403
- 'post_modified_gmt',
404
- 'post_content_filtered',
405
- 'post_parent',
406
- 'guid',
407
- 'menu_order',
408
- 'post_type',
409
- 'post_mime_type',
410
- 'comment_count',
411
- );
412
-
413
- return in_array( $key, $columns );
414
- }
 
 
 
 
 
 
 
 
415
  }
416
 
 
 
 
 
 
417
 
418
- /* Shortcuts for common functions */
 
 
419
 
420
- if ( ! function_exists( 'yit_get_order_id' ) ) {
421
- /**
422
- * Retrieve the order id
423
- *
424
- * @param WC_Order $order
425
- *
426
- * @return mixed
427
- */
428
- function yit_get_order_id( $order ) {
429
- return yit_get_prop( $order, 'id' );
430
- }
431
  }
432
 
433
- if ( ! function_exists( 'yit_get_product_id' ) ) {
434
- /**
435
- * Retrieve the product id
436
- *
437
- * @param WC_Product $product
438
- *
439
- * @return mixed
440
- */
441
- function yit_get_product_id( $product ) {
442
- return yit_get_prop( $product, 'id' );
443
- }
444
- }
445
 
446
- if ( ! function_exists( 'yit_get_base_product_id' ) ) {
447
- /**
448
- * New way to retrieve the $product->id as it was before WC 2.7.
449
- *
450
- * Retrieve the parent product id for WC_Product_Variation instances
451
- * or the product id in the other cases.
452
- *
453
- * @param WC_Product $product
454
- *
455
- * @return mixed
456
- */
457
- function yit_get_base_product_id( $product ) {
458
-
459
- return $product instanceof WC_Data && $product->is_type( 'variation' ) ?
460
- yit_get_prop( $product, 'parent_id' ) :
461
- yit_get_prop( $product, 'id' );
462
- }
463
- }
464
 
465
- if ( ! function_exists( 'yit_get_display_price' ) ) {
466
- /**
467
- * @param WC_Product $product
468
- * @param string $price
469
- * @param int $qty
470
- */
471
- function yit_get_display_price( $product, $price = '', $qty = 1 ) {
472
 
473
- if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
 
 
 
 
474
 
475
- $price = wc_get_price_to_display( $product, array( 'qty' => $qty, 'price' => $price ) );
476
- } else {
 
477
 
478
- $price = $product->get_display_price( $price, $qty );
479
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
 
481
- return $price;
482
- }
483
  }
484
 
485
- if ( ! function_exists( 'yit_get_price_excluding_tax' ) ) {
486
- /**
487
- * @param WC_Product $product
488
- * @param int $qty
489
- * @param string $price
490
- *
491
- * @return float|string
492
- */
493
- function yit_get_price_excluding_tax( $product, $qty = 1, $price = '' ) {
494
 
495
- if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
496
 
497
- $price = wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
498
- } else {
 
 
 
 
 
 
 
 
 
 
499
 
500
- $price = $product->get_price_excluding_tax( $qty, $price );
501
- }
 
 
 
 
 
 
 
 
 
 
502
 
503
- return $price;
504
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
505
  }
506
 
507
- if ( ! function_exists( 'yit_get_price_including_tax' ) ) {
508
- /**
509
- * @param WC_Product $product
510
- * @param int $qty
511
- * @param string $price
512
- *
513
- * @return float|string
514
- */
515
- function yit_get_price_including_tax( $product, $qty = 1, $price = '' ) {
516
 
517
- if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
518
 
519
- $price = wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
520
- } else {
521
 
522
- $price = $product->get_price_including_tax( $qty, $price );
523
- }
524
 
525
- return $price;
526
- }
527
  }
528
 
529
- if ( ! function_exists( 'yit_get_product_image_id' ) ) {
530
- /**
531
- * get the attach image id
532
- *
533
- * @param WC_Product $product
534
- * @param string $context ( view/edit )
535
- */
536
- function yit_get_product_image_id( $product, $context = 'view' ) {
 
537
 
538
- if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
539
 
540
- $image_id = $product->get_image_id( $context );
541
- } else {
542
 
543
- $image_id = $product->get_image_id();
544
- }
545
 
546
- return $image_id;
547
- }
548
  }
549
 
550
- if ( !function_exists( 'yit_get_refund_amount' ) ){
551
  /**
552
- * @param $refund \WC_Order_Refund
553
- * @param $context string
 
554
  *
555
- * @return float
556
  */
557
- function yit_get_refund_amount( $refund, $context = 'view' ){
558
- $is_wc_data = $refund instanceof WC_Data;
559
 
560
- if( $is_wc_data ){
561
- return $refund->get_amount( $context );
562
- }
563
- else{
564
- return $refund->get_refund_amount();
 
565
  }
 
 
566
  }
567
  }
568
 
569
- if ( !function_exists( 'yit_set_refund_amount' ) ){
570
  /**
571
- * @param $refund \WC_Order_Refund
572
- * @param $amount float
573
  *
574
- * @return float
 
575
  */
576
- function yit_set_refund_amount( $refund, $amount ){
577
- $is_wc_data = $refund instanceof WC_Data;
578
 
579
- if( $is_wc_data ){
580
- $refund->set_amount( $amount );
581
- }
582
- else{
583
- $refund->refund_amount = $amount;
 
584
  }
 
 
585
  }
586
  }
587
 
588
- if ( !function_exists( 'yit_get_refund_reason' ) ){
589
  /**
590
  * @param $refund \WC_Order_Refund
591
- * @param $amount float
592
  *
593
  * @return float
594
  */
595
- function yit_get_refund_reason( $refund ){
596
  $is_wc_data = $refund instanceof WC_Data;
597
 
598
- if( $is_wc_data ){
599
- return $refund->get_reason();
600
- }
601
- else{
602
- return $refund->get_refund_reason();
603
  }
604
  }
605
  }
606
 
607
- if( ! function_exists( 'yit_add_select2_fields' ) ){
608
  /**
609
  * Add select 2
610
  *
611
  * @param array $args
612
  */
613
- function yit_add_select2_fields( $args = array() ){
614
  $default = array(
615
  'type' => 'hidden',
616
  'class' => '',
@@ -622,38 +588,46 @@ if( ! function_exists( 'yit_add_select2_fields' ) ){
622
  'data-multiple' => false,
623
  'data-action' => '',
624
  'value' => '',
625
- 'style' => ''
 
626
  );
627
 
628
  $args = wp_parse_args( $args, $default );
629
 
630
- if( version_compare( WC()->version, '2.7.0', '>=' ) ) :
631
- if( $args['data-multiple']=== true && substr( $args['name'], -2 ) != '[]'){
632
- $args['name'] = $args['name'] . '[]';
 
 
 
 
 
 
633
  }
634
  ?>
635
 
636
  <select
637
- id="<?php echo $args['id'] ?>"
638
- class="<?php echo $args['class'] ?>"
639
- name="<?php echo $args['name'] ?>"
640
- data-placeholder="<?php echo $args['data-placeholder'] ?>"
641
- data-allow_clear="<?php echo $args['data-allow_clear'] ?>"
642
- <?php echo ! empty( $args['data-action'] ) ? 'data-action="' . $args['data-action'] . '"' : ''; ?>
643
- <?php echo ! empty( $args['data-multiple'] ) ? 'multiple="multiple"' : ''; ?>
644
- style="<?php echo $args['style'] ?>"
 
645
  >
646
 
647
- <?php if( ! empty( $args['value'] ) ) {
648
- $values = $args['value'];
649
 
650
- if( ! is_array( $values ) ){
651
  $values = explode( ',', $values );
652
  }
653
 
654
- foreach( $values as $value ): ?>
655
  <option value="<?php echo $value; ?>" <?php selected( true, true, true ) ?> >
656
- <?php echo $args['data-selected'][ $value ]; ?>
657
  </option>
658
  <?php endforeach;
659
  }
@@ -661,28 +635,66 @@ if( ! function_exists( 'yit_add_select2_fields' ) ){
661
  </select>
662
  <?php
663
  else :
664
- if( is_array( $args['data-selected'] ) ){
665
- $args['data-selected'] = $args['data-multiple'] === true ? json_encode( $args['data-selected'] ) : array_shift( $args['data-selected'] );
666
- }
667
- ?>
 
668
  <input
669
  type="hidden"
670
- id="<?php echo $args['id'] ?>"
671
- class="<?php echo $args['class'] ?>"
672
- name="<?php echo $args['name'] ?>"
673
- data-placeholder="<?php echo $args['data-placeholder'] ?>"
674
- data-allow_clear="<?php echo $args['data-allow_clear'] ?>"
675
- data-selected="<?php echo $args['data-selected'] ?>"
676
- data-multiple="<?php echo $args['data-multiple'] === true ? 'true' : 'false' ?>"
677
- <?php if( ! empty( $args['data-action'] ) ? 'data-action="' . $args['data-action'] . '"' : '' ) ?>
678
- value="<?php echo $args['value'] ?>"
679
- style="<?php echo $args['style'] ?>"
 
680
  />
681
  <?php
682
  endif;
683
  }
684
  }
685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
686
 
687
  yit_fix_wc_deprecated_filters();
688
- add_action( 'shutdown', 'yit_send_changes_to_db' );
8
  * http://www.gnu.org/licenses/gpl-3.0.txt
9
  */
10
 
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
  } // Exit if accessed directly
14
 
15
+ if ( !function_exists( 'WC' ) ) {
16
+ return;
17
  }
18
 
19
  $changed_objects = array();
20
 
21
+ if ( !function_exists( 'yit_get_prop' ) ) {
22
+ /**
23
+ *
24
+ */
25
+ function yit_get_prop( $object, $key, $single = true, $context = 'view' ) {
26
+
27
+ $prop_map = yit_return_new_attribute_map();
28
+ $is_wc_data = $object instanceof WC_Data;
29
+
30
+ if ( $is_wc_data ) {
31
+ $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
32
+
33
+ if ( ( $getter = "get{$key}" ) && method_exists( $object, $getter ) ) {
34
+ return $object->$getter( $context );
35
+ } elseif ( ( $getter = "get_{$key}" ) && method_exists( $object, $getter ) ) {
36
+ return $object->$getter( $context );
37
+ } else {
38
+ return $object->get_meta( $key, $single );
39
+ }
40
+ } else {
41
+ $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
42
+
43
+ if ( isset( $object->$key ) ) {
44
+ return $object->$key;
45
+ } elseif ( yit_wc_check_post_columns( $key ) ) {
46
+ return $object->post->$key;
47
+ } else {
48
+ $getter = 'get_user_meta';
49
+ !$object instanceof WC_Customer && $getter = 'get_post_meta';
50
+
51
+ $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id;
52
+
53
+ return $getter( $object_id, $key, true );
54
+ }
55
+ }
56
+ }
57
  }
58
 
59
+ if ( !function_exists( 'yit_set_prop' ) ) {
60
+ /**
61
+ *
62
+ */
63
+ function yit_set_prop( $object, $arg1, $arg2 = false ) {
64
+
65
+ if ( !is_array( $arg1 ) ) {
66
+ $arg1 = array(
67
+ $arg1 => $arg2
68
+ );
69
+ }
70
+
71
+ $prop_map = yit_return_new_attribute_map();
72
+ $is_wc_data = $object instanceof WC_Data;
73
+
74
+ foreach ( $arg1 as $key => $value ) {
75
+ if ( $is_wc_data ) {
76
+ $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
77
+
78
+ if ( ( $setter = "set{$key}" ) && method_exists( $object, $setter ) ) {
79
+ $object->$setter( $value );
80
+ } elseif ( ( $setter = "set_{$key}" ) && method_exists( $object, $setter ) ) {
81
+ $object->$setter( $value );
82
+ } else {
83
+ $object->update_meta_data( $key, $value );
84
+ }
85
+ } else {
86
+ $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
87
+ ( strpos( $key, '_' ) === 0 ) && $key = substr( $key, 1 );
88
+
89
+ if ( yit_wc_check_post_columns( $key ) ) {
90
+ $object->post->$key = $value;
91
+ } else {
92
+ $object->$key = $value;
93
+ }
94
+ }
95
+ }
96
+ }
97
  }
98
 
99
+ if ( !function_exists( 'yit_save_prop' ) ) {
100
+ /**
101
+ *
102
+ */
103
+ function yit_save_prop( $object, $arg1, $arg2 = false, $force_update = false ) {
104
+ if ( !is_array( $arg1 ) ) {
105
+ $arg1 = array(
106
+ $arg1 => $arg2
107
+ );
108
+ }
109
 
110
+ $is_wc_data = $object instanceof WC_Data;
111
 
112
+ foreach ( $arg1 as $key => $value ) {
113
+ yit_set_prop( $object, $key, $value );
114
 
115
+ if ( $is_wc_data ) {
116
+ if ( $force_update ) {
117
  $object->save();
118
+ } else {
 
119
  yit_store_changes( $object, $key, $value );
120
  }
121
+ } else {
122
+ if ( yit_wc_check_post_columns( $key ) ) {
123
+ yit_store_changes( $object->post, $key, $value );
124
+ } else {
125
+ $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id;
 
 
 
 
 
 
 
126
 
127
+ update_post_meta( $object_id, $key, $value );
128
+ }
129
+ }
130
+ }
131
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  }
133
 
134
+ if ( !function_exists( 'yit_delete_prop' ) ) {
135
+ /**
136
+ *
137
+ */
138
+ function yit_delete_prop( $object, $key, $value = '' ) {
139
+ $prop_map = yit_return_new_attribute_map();
140
+ $is_wc_data = $object instanceof WC_Data;
141
+
142
+ if ( $is_wc_data ) {
143
+ $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
144
+
145
+ if ( ( $setter = "set{$key}" ) && ( $getter = "get{$key}" ) && method_exists( $object, $setter ) && ( !$value || $object->$getter == $value ) ) {
146
+ $object->$setter( '' );
147
+ } elseif ( ( $setter = "set_{$key}" ) && ( $getter = "get_{$key}" ) && method_exists( $object, $setter ) && ( !$value || $object->$getter == $value ) ) {
148
+ $object->$setter( '' );
149
+ } elseif ( ( !$value || $object->get_meta( $key ) == $value ) ) {
150
+ $object->delete_meta_data( $key, $value );
151
+ }
152
+
153
+ yit_store_changes( $object, $key );
154
+ } else {
155
+ if ( yit_wc_check_post_columns( $key ) && ( !$value || $object->post->$key == $value ) ) {
156
+ yit_store_changes( $object->post, $key, '' );
157
+ } else {
158
+ $object_id = is_callable( array( $object, 'get_id' ) ) ? $object->get_id() : $object->id;
159
+
160
+ delete_post_meta( $object_id, $key, $value );
161
+ }
162
+ }
163
+ }
164
  }
165
 
166
+ if ( !function_exists( 'yit_return_new_attribute_map' ) ) {
167
+ function yit_return_new_attribute_map() {
168
+ return array(
169
+ 'post_parent' => 'parent_id',
170
+ 'post_title' => 'name',
171
+ 'post_status' => 'status',
172
+ 'post_content' => 'description',
173
+ 'post_excerpt' => 'short_description',
174
+ /* Orders */
175
+ 'paid_date' => 'date_paid',
176
+ '_paid_date' => '_date_paid',
177
+ 'completed_date' => 'date_completed',
178
+ '_completed_date' => '_date_completed',
179
+ '_order_date' => '_date_created',
180
+ 'order_date' => 'date_created',
181
+ 'order_total' => 'total',
182
+ /* Products */
183
+ 'visibility' => 'catalog_visibility',
184
+ '_visibility' => '_catalog_visibility',
185
+ 'sale_price_dates_from' => 'date_on_sale_from',
186
+ '_sale_price_dates_from' => '_date_on_sale_from',
187
+ 'sale_price_dates_to' => 'date_on_sale_to',
188
+ '_sale_price_dates_to' => '_date_on_sale_to',
189
+ /*Coupons*/
190
+ 'coupon_amount' => 'amount',
191
+ 'exclude_product_ids' => 'excluded_product_ids',
192
+ 'exclude_product_categories' => 'excluded_product_categories',
193
+ 'customer_email' => 'email_restrictions',
194
+ 'expiry_date' => 'date_expires',
195
+ );
196
+ }
197
+ }
198
 
199
+ if ( !function_exists( 'yit_store_changes' ) ) {
200
+ function yit_store_changes( $object, $key, $value = false ) {
201
+ global $changed_objects;
202
 
203
+ $is_wc_data = $object instanceof WC_Data;
 
 
 
 
204
 
205
+ if ( $is_wc_data ) {
206
+ /**
207
+ * @var $object \WC_Data
208
+ */
209
+ $object_reference = $object->get_id();
210
 
211
+ $cache_type = is_a( $object, 'WC_Product' ) ? 'product' : 'order';
212
+ $cache_key = $cache_type . '-' . $object_reference;
213
+ $cache_group = $cache_type . 's';
214
 
215
+ $changed_objects[ $object_reference ][ 'object' ] = $object;
216
+ $changed_objects[ $object_reference ][ 'changes' ][ $key ] = $value;
217
 
 
 
 
 
 
 
218
 
219
+ wp_cache_set( $cache_key, $object, $cache_group );
220
+ } else {
221
+ $changed_objects[ $object->ID ][ $key ] = $value;
222
+ }
223
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  }
225
 
226
+ if ( !function_exists( 'yit_send_changes_to_db' ) ) {
227
+ function yit_send_changes_to_db() {
228
+ global $changed_objects;
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
+ if ( !empty( $changed_objects ) ) {
231
+ foreach ( $changed_objects as $id => $data ) {
232
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
233
+ /**
234
+ * @var $object \WC_Data
235
+ */
236
+ $object = is_a( $data[ 'object' ], 'WC_Product' ) ? wc_get_product( $id ) : wc_get_order( $id );
 
 
 
 
 
 
 
 
237
 
238
+ yit_set_prop( $object, $data[ 'changes' ] );
239
+ $object->save();
240
+ } else {
241
+ $data[ 'ID' ] = $id;
242
+ wp_update_post( $data );
243
+ }
244
+ }
245
+ }
246
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
248
 
249
+ if ( !function_exists( 'yit_get_orders' ) ) {
250
+ /**
251
+ *
252
+ */
253
+ function yit_get_orders( $args ) {
254
+ if ( version_compare( WC()->version, '2.6', '<' ) ) {
255
+ $args[ 'fields' ] = 'objects';
256
+ $posts = get_posts( $args );
257
+
258
+ return array_map( 'wc_get_order', $posts );
259
+ } else {
260
+ return wc_get_orders( $args );
261
+ }
262
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  }
264
 
265
+ if ( !function_exists( 'yit_get_products' ) ) {
266
+ /**
267
+ *
268
+ */
269
+ function yit_get_products( $args ) {
270
+ if ( version_compare( WC()->version, '2.6', '<' ) ) {
271
+ $args[ 'fields' ] = 'objects';
272
+ $posts = get_posts( $args );
273
+
274
+ return array_map( 'wc_get_product', $posts );
275
+ } else {
276
+ return wc_get_products( $args );
277
+ }
278
+ }
 
279
  }
280
 
281
+ if ( !function_exists( 'yit_update_product_stock' ) ) {
282
+ /**
283
+ *
284
+ */
285
+ function yit_update_product_stock( $product, $stock_quantity = 1, $operation = 'set' ) {
286
+ if ( function_exists( 'wc_update_product_stock' ) ) {
287
+ $stock = wc_update_product_stock( $product, $stock_quantity, $operation );
288
+ } else {
289
+ switch ( $operation ) {
290
+ case 'increase':
291
+ $stock = $product->increase_stock( $stock_quantity );
292
+ break;
293
+ case 'decrease':
294
+ $stock = $product->reduce_stock( $stock_quantity );
295
+ break;
296
+ case 'set':
297
+ default:
298
+ $stock = $product->set_stock( $stock_quantity );
299
+ break;
300
+ }
301
+ }
302
 
303
+ return $stock;
304
+ }
305
  }
306
 
307
+ if ( !function_exists( 'yit_wc_deprecated_filters' ) ) {
308
+ /**
309
+ *
310
+ */
311
+ function yit_wc_deprecated_filters() {
312
+ return apply_filters( 'yit_wc_deprecated_filters', array(
313
+ 'woocommerce_email_order_schema_markup' => 'woocommerce_structured_data_order',
314
+ 'woocommerce_product_width' => 'woocommerce_product_get_width',
315
+ 'woocommerce_product_height' => 'woocommerce_product_get_height',
316
+ 'woocommerce_product_length' => 'woocommerce_product_get_length',
317
+ 'woocommerce_product_weight' => 'woocommerce_product_get_weight',
318
+ 'woocommerce_get_sku' => 'woocommerce_product_get_sku',
319
+ 'woocommerce_get_price' => 'woocommerce_product_get_price',
320
+ 'woocommerce_get_regular_price' => 'woocommerce_product_get_regular_price',
321
+ 'woocommerce_get_sale_price' => 'woocommerce_product_get_sale_price',
322
+ 'woocommerce_product_tax_class' => 'woocommerce_product_get_tax_class',
323
+ 'woocommerce_get_stock_quantity' => 'woocommerce_product_get_stock_quantity',
324
+ 'woocommerce_get_product_attributes' => 'woocommerce_product_get_attributes',
325
+ 'woocommerce_product_gallery_attachment_ids' => 'woocommerce_product_get_gallery_image_ids',
326
+ 'woocommerce_product_review_count' => 'woocommerce_product_get_review_count',
327
+ 'woocommerce_product_files' => 'woocommerce_product_get_downloads',
328
+ 'woocommerce_get_currency' => 'woocommerce_order_get_currency',
329
+ 'woocommerce_order_amount_discount_total' => 'woocommerce_order_get_discount_total',
330
+ 'woocommerce_order_amount_discount_tax' => 'woocommerce_order_get_discount_tax',
331
+ 'woocommerce_order_amount_shipping_total' => 'woocommerce_order_get_shipping_total',
332
+ 'woocommerce_order_amount_shipping_tax' => 'woocommerce_order_get_shipping_tax',
333
+ 'woocommerce_order_amount_cart_tax' => 'woocommerce_order_get_cart_tax',
334
+ 'woocommerce_order_amount_total' => 'woocommerce_order_get_total',
335
+ 'woocommerce_order_amount_total_tax' => 'woocommerce_order_get_total_tax',
336
+ 'woocommerce_order_amount_total_discount' => 'woocommerce_order_get_total_discount',
337
+ 'woocommerce_order_amount_subtotal' => 'woocommerce_order_get_subtotal',
338
+ 'woocommerce_order_tax_totals' => 'woocommerce_order_get_tax_totals',
339
+ 'woocommerce_refund_amount' => 'woocommerce_get_order_refund_get_amount',
340
+ 'woocommerce_refund_reason' => 'woocommerce_get_order_refund_get_reason',
341
+ 'default_checkout_country' => 'default_checkout_billing_country',
342
+ 'default_checkout_state' => 'default_checkout_billing_state',
343
+ 'default_checkout_postcode' => 'default_checkout_billing_postcode',
344
+
345
+ ) );
346
+ }
347
  }
348
 
349
+ if ( !function_exists( 'yit_fix_wc_deprecated_filters' ) ) {
350
+ /**
351
+ *
352
+ */
353
+ function yit_fix_wc_deprecated_filters() {
354
 
355
+ if ( !version_compare( WC()->version, '2.7.0', '<' ) ) {
356
+ return;
357
+ }
358
 
359
+ $deprecated_filters = yit_wc_deprecated_filters();
360
+ foreach ( $deprecated_filters as $old => $new ) {
361
+ add_filter( $old, 'yit_wc_deprecated_filter_mapping', 10, 100 );
362
+ }
363
+ }
 
 
 
 
 
 
364
  }
365
 
366
+ if ( !function_exists( 'yit_wc_deprecated_filter_mapping' ) ) {
367
+ /**
368
+ *
369
+ */
370
+ function yit_wc_deprecated_filter_mapping() {
371
+ $deprecated_filters = yit_wc_deprecated_filters();
 
 
 
 
 
 
372
 
373
+ $filter = current_filter();
374
+ $args = func_get_args();
375
+ $data = $args[ 0 ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
 
 
 
 
 
 
 
 
377
 
378
+ if ( isset( $deprecated_filters[ $filter ] ) ) {
379
+ if ( has_filter( $deprecated_filters[ $filter ] ) ) {
380
+ $data = apply_filters_ref_array( $deprecated_filters[ $filter ], $args );
381
+ }
382
+ }
383
 
384
+ return $data;
385
+ }
386
+ }
387
 
388
+ if ( !function_exists( 'yit_wc_check_post_columns' ) ) {
389
+ /**
390
+ *
391
+ */
392
+ function yit_wc_check_post_columns( $key ) {
393
+ $columns = array(
394
+ 'post_author',
395
+ 'post_date',
396
+ 'post_date_gmt',
397
+ 'post_content',
398
+ 'post_title',
399
+ 'post_excerpt',
400
+ 'post_status',
401
+ 'comment_status',
402
+ 'ping_status',
403
+ 'post_password',
404
+ 'post_name',
405
+ 'to_ping',
406
+ 'pinged',
407
+ 'post_modified',
408
+ 'post_modified_gmt',
409
+ 'post_content_filtered',
410
+ 'post_parent',
411
+ 'guid',
412
+ 'menu_order',
413
+ 'post_type',
414
+ 'post_mime_type',
415
+ 'comment_count',
416
+ );
417
 
418
+ return in_array( $key, $columns );
419
+ }
420
  }
421
 
 
 
 
 
 
 
 
 
 
422
 
423
+ /* Shortcuts for common functions */
424
 
425
+ if ( !function_exists( 'yit_get_order_id' ) ) {
426
+ /**
427
+ * Retrieve the order id
428
+ *
429
+ * @param WC_Order $order
430
+ *
431
+ * @return mixed
432
+ */
433
+ function yit_get_order_id( $order ) {
434
+ return yit_get_prop( $order, 'id' );
435
+ }
436
+ }
437
 
438
+ if ( !function_exists( 'yit_get_product_id' ) ) {
439
+ /**
440
+ * Retrieve the product id
441
+ *
442
+ * @param WC_Product $product
443
+ *
444
+ * @return mixed
445
+ */
446
+ function yit_get_product_id( $product ) {
447
+ return yit_get_prop( $product, 'id' );
448
+ }
449
+ }
450
 
451
+ if ( !function_exists( 'yit_get_base_product_id' ) ) {
452
+ /**
453
+ * New way to retrieve the $product->id as it was before WC 2.7.
454
+ *
455
+ * Retrieve the parent product id for WC_Product_Variation instances
456
+ * or the product id in the other cases.
457
+ *
458
+ * @param WC_Product $product
459
+ *
460
+ * @return mixed
461
+ */
462
+ function yit_get_base_product_id( $product ) {
463
+
464
+ return $product instanceof WC_Data && $product->is_type( 'variation' ) ?
465
+ yit_get_prop( $product, 'parent_id' ) :
466
+ yit_get_prop( $product, 'id' );
467
+ }
468
  }
469
 
470
+ if ( !function_exists( 'yit_get_display_price' ) ) {
471
+ /**
472
+ * @param WC_Product $product
473
+ * @param string $price
474
+ * @param int $qty
475
+ */
476
+ function yit_get_display_price( $product, $price = '', $qty = 1 ) {
 
 
477
 
478
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
479
 
480
+ $price = wc_get_price_to_display( $product, array( 'qty' => $qty, 'price' => $price ) );
481
+ } else {
482
 
483
+ $price = $product->get_display_price( $price, $qty );
484
+ }
485
 
486
+ return $price;
487
+ }
488
  }
489
 
490
+ if ( !function_exists( 'yit_get_price_excluding_tax' ) ) {
491
+ /**
492
+ * @param WC_Product $product
493
+ * @param int $qty
494
+ * @param string $price
495
+ *
496
+ * @return float|string
497
+ */
498
+ function yit_get_price_excluding_tax( $product, $qty = 1, $price = '' ) {
499
 
500
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
501
 
502
+ $price = wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
503
+ } else {
504
 
505
+ $price = $product->get_price_excluding_tax( $qty, $price );
506
+ }
507
 
508
+ return $price;
509
+ }
510
  }
511
 
512
+ if ( !function_exists( 'yit_get_price_including_tax' ) ) {
513
  /**
514
+ * @param WC_Product $product
515
+ * @param int $qty
516
+ * @param string $price
517
  *
518
+ * @return float|string
519
  */
520
+ function yit_get_price_including_tax( $product, $qty = 1, $price = '' ) {
 
521
 
522
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
523
+
524
+ $price = wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
525
+ } else {
526
+
527
+ $price = $product->get_price_including_tax( $qty, $price );
528
  }
529
+
530
+ return $price;
531
  }
532
  }
533
 
534
+ if ( !function_exists( 'yit_get_product_image_id' ) ) {
535
  /**
536
+ * get the attach image id
 
537
  *
538
+ * @param WC_Product $product
539
+ * @param string $context ( view/edit )
540
  */
541
+ function yit_get_product_image_id( $product, $context = 'view' ) {
 
542
 
543
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
544
+
545
+ $image_id = $product->get_image_id( $context );
546
+ } else {
547
+
548
+ $image_id = $product->get_image_id();
549
  }
550
+
551
+ return $image_id;
552
  }
553
  }
554
 
555
+ if ( !function_exists( 'yit_get_refund_amount' ) ) {
556
  /**
557
  * @param $refund \WC_Order_Refund
558
+ * @param $context string
559
  *
560
  * @return float
561
  */
562
+ function yit_get_refund_amount( $refund, $context = 'view' ) {
563
  $is_wc_data = $refund instanceof WC_Data;
564
 
565
+ if ( $is_wc_data ) {
566
+ return $refund->get_amount( $context );
567
+ } else {
568
+ return $refund->get_refund_amount();
 
569
  }
570
  }
571
  }
572
 
573
+ if ( !function_exists( 'yit_add_select2_fields' ) ) {
574
  /**
575
  * Add select 2
576
  *
577
  * @param array $args
578
  */
579
+ function yit_add_select2_fields( $args = array() ) {
580
  $default = array(
581
  'type' => 'hidden',
582
  'class' => '',
588
  'data-multiple' => false,
589
  'data-action' => '',
590
  'value' => '',
591
+ 'style' => '',
592
+ 'custom-attributes' => array()
593
  );
594
 
595
  $args = wp_parse_args( $args, $default );
596
 
597
+ $custom_attributes = array();
598
+ foreach ( $args[ 'custom-attributes' ] as $attribute => $attribute_value ) {
599
+ $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
600
+ }
601
+ $custom_attributes = implode( ' ', $custom_attributes );
602
+
603
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) :
604
+ if ( $args[ 'data-multiple' ] === true && substr( $args[ 'name' ], -2 ) != '[]' ) {
605
+ $args[ 'name' ] = $args[ 'name' ] . '[]';
606
  }
607
  ?>
608
 
609
  <select
610
+ id="<?php echo $args[ 'id' ] ?>"
611
+ class="<?php echo $args[ 'class' ] ?>"
612
+ name="<?php echo $args[ 'name' ] ?>"
613
+ data-placeholder="<?php echo $args[ 'data-placeholder' ] ?>"
614
+ data-allow_clear="<?php echo $args[ 'data-allow_clear' ] ?>"
615
+ <?php echo !empty( $args[ 'data-action' ] ) ? 'data-action="' . $args[ 'data-action' ] . '"' : ''; ?>
616
+ <?php echo !empty( $args[ 'data-multiple' ] ) ? 'multiple="multiple"' : ''; ?>
617
+ style="<?php echo $args[ 'style' ] ?>"
618
+ <?php echo $custom_attributes ?>
619
  >
620
 
621
+ <?php if ( !empty( $args[ 'value' ] ) ) {
622
+ $values = $args[ 'value' ];
623
 
624
+ if ( !is_array( $values ) ) {
625
  $values = explode( ',', $values );
626
  }
627
 
628
+ foreach ( $values as $value ): ?>
629
  <option value="<?php echo $value; ?>" <?php selected( true, true, true ) ?> >
630
+ <?php echo $args[ 'data-selected' ][ $value ]; ?>
631
  </option>
632
  <?php endforeach;
633
  }
635
  </select>
636
  <?php
637
  else :
638
+ if ( $args[ 'data-multiple' ] === false && is_array( $args[ 'data-selected' ] ) ) {
639
+ $args[ 'data-selected' ] = current($args[ 'data-selected' ]);
640
+ }
641
+
642
+ ?>
643
  <input
644
  type="hidden"
645
+ id="<?php echo $args[ 'id' ] ?>"
646
+ class="<?php echo $args[ 'class' ] ?>"
647
+ name="<?php echo $args[ 'name' ] ?>"
648
+ data-placeholder="<?php echo $args[ 'data-placeholder' ] ?>"
649
+ data-allow_clear="<?php echo $args[ 'data-allow_clear' ] ?>"
650
+ data-selected="<?php echo is_array( $args[ 'data-selected' ] ) ? esc_attr( json_encode( $args[ 'data-selected' ] ) ) : esc_attr( $args[ 'data-selected' ] ) ?>"
651
+ data-multiple="<?php echo $args[ 'data-multiple' ] === true ? 'true' : 'false' ?>"
652
+ <?php echo( !empty( $args[ 'data-action' ] ) ? 'data-action="' . $args[ 'data-action' ] . '"' : '' ) ?>
653
+ value="<?php echo $args[ 'value' ] ?>"
654
+ style="<?php echo $args[ 'style' ] ?>"
655
+ <?php echo $custom_attributes ?>
656
  />
657
  <?php
658
  endif;
659
  }
660
  }
661
 
662
+ if ( !function_exists( 'yit_product_visibility_meta' ) ) {
663
+ function yit_product_visibility_meta( $args ) {
664
+ if ( version_compare( WC()->version, '2.7.0', '<' ) ) {
665
+ $args[ 'meta_query' ] = isset( $args[ 'meta_query' ] ) ? $args[ 'meta_query' ] : array();
666
+ $args[ 'meta_query' ][] = WC()->query->visibility_meta_query();
667
+ } else {
668
+ $product_visibility_term_ids = wc_get_product_visibility_term_ids();
669
+ $args[ 'tax_query' ] = isset( $args[ 'tax_query' ] ) ? $args[ 'tax_query' ] : array();
670
+ $args[ 'tax_query' ][] = array(
671
+ 'taxonomy' => 'product_visibility',
672
+ 'field' => 'term_taxonomy_id',
673
+ 'terms' => is_search() ? $product_visibility_term_ids[ 'exclude-from-search' ] : $product_visibility_term_ids[ 'exclude-from-catalog' ],
674
+ 'operator' => 'NOT IN',
675
+ );
676
+ }
677
+
678
+ return $args;
679
+ }
680
+ }
681
+
682
+ if ( !function_exists( 'yit_datetime_to_timestamp' ) ) {
683
+
684
+ /**
685
+ *
686
+ */
687
+ function yit_datetime_to_timestamp( $date ) {
688
+
689
+ if ( version_compare( WC()->version, '2.7.0', '<' ) ) {
690
+ $date = strtotime( $date );
691
+ }
692
+
693
+ return $date;
694
+ }
695
+
696
+ }
697
+
698
 
699
  yit_fix_wc_deprecated_filters();
700
+ add_action( 'shutdown', 'yit_send_changes_to_db' );