YITH WooCommerce Zoom Magnifier - Version 1.2.26

Version Description

Download this release

Release Info

Developer yithemes
Plugin Icon 128x128 YITH WooCommerce Zoom Magnifier
Version 1.2.26
Comparing to
See all releases

Code changes from version 1.2.25 to 1.2.26

README.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: yithemes
4
  Tags: zoom, magnifier, woocommerce, product image, themes, yit, e-commerce, shop, thumbnail, thumbnail slider, zoom image, carousel, image carousel
5
  Requires at least: 3.5.1
6
  Tested up to: 4.7.2
7
- Stable tag: 1.2.25
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -51,6 +51,10 @@ YITH WooCommerce Zoom Magnifier will add a new tab called "Zoom Magnifier" in "Y
51
 
52
  == Changelog ==
53
 
 
 
 
 
54
  = Version 1.2.25 - Released: Mar 08, 2017 =
55
 
56
  * Fix: removed unused class.yith-wcmg.php file
4
  Tags: zoom, magnifier, woocommerce, product image, themes, yit, e-commerce, shop, thumbnail, thumbnail slider, zoom image, carousel, image carousel
5
  Requires at least: 3.5.1
6
  Tested up to: 4.7.2
7
+ Stable tag: 1.2.26
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
51
 
52
  == Changelog ==
53
 
54
+ = Version 1.2.26 - Released: Mar 28, 2017 =
55
+
56
+ * Fix: YITH Plugin Framework initialization that prevents the plugin update.
57
+
58
  = Version 1.2.25 - Released: Mar 08, 2017 =
59
 
60
  * Fix: removed unused class.yith-wcmg.php file
class.yith-wcmg-frontend.php CHANGED
@@ -152,8 +152,8 @@ if ( ! class_exists ( 'YITH_WCMG_Frontend' ) ) {
152
  * @since 1.0.0
153
  */
154
  public function available_variation ( $data, $wc_prod, $variation ) {
155
-
156
- $attachment_id = get_post_thumbnail_id ( $variation->get_variation_id () );
157
  $attachment = wp_get_attachment_image_src ( $attachment_id, 'shop_magnifier' );
158
 
159
  $data[ 'image_magnifier' ] = $attachment ? current ( $attachment ) : '';
152
  * @since 1.0.0
153
  */
154
  public function available_variation ( $data, $wc_prod, $variation ) {
155
+
156
+ $attachment_id = get_post_thumbnail_id ( version_compare ( WC ()->version, '3.0', '<' ) ? $variation->get_variation_id () : $variation->get_id () );
157
  $attachment = wp_get_attachment_image_src ( $attachment_id, 'shop_magnifier' );
158
 
159
  $data[ 'image_magnifier' ] = $attachment ? current ( $attachment ) : '';
init.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: YITH WooCommerce Zoom Magnifier
4
  * Plugin URI: http://yithemes.com/themes/plugins/yith-woocommerce-zoom-magnifier/
5
  * Description: YITH WooCommerce Zoom Magnifier enables you to add a zoom effect to product images and a thumbnail slider for the product image gallery.
6
- * Version: 1.2.25
7
  * Author: YITHEMES
8
  * Author URI: http://yithemes.com/
9
  * Text Domain: yith-woocommerce-zoom-magnifier
@@ -11,7 +11,7 @@
11
  *
12
  * @author Your Inspiration Themes
13
  * @package YITH WooCommerce Magnifier
14
- * @version 1.2.25
15
  */
16
  /* Copyright 2013-2015 Your Inspiration Themes (email : plugins@yithemes.com)
17
 
@@ -76,7 +76,7 @@ if ( ! function_exists ( 'yith_plugin_registration_hook' ) ) {
76
  register_activation_hook ( __FILE__, 'yith_plugin_registration_hook' );
77
 
78
  defined ( 'YITH_YWZM_FREE_INIT' ) || define ( 'YITH_YWZM_FREE_INIT', plugin_basename ( __FILE__ ) );
79
- defined ( 'YITH_YWZM_VERSION' ) || define ( 'YITH_YWZM_VERSION', '1.2.25' );
80
  defined ( 'YITH_YWZM_FILE' ) || define ( 'YITH_YWZM_FILE', __FILE__ );
81
  defined ( 'YITH_YWZM_DIR' ) || define ( 'YITH_YWZM_DIR', plugin_dir_path ( __FILE__ ) );
82
  defined ( 'YITH_YWZM_URL' ) || define ( 'YITH_YWZM_URL', plugins_url ( '/', __FILE__ ) );
3
  * Plugin Name: YITH WooCommerce Zoom Magnifier
4
  * Plugin URI: http://yithemes.com/themes/plugins/yith-woocommerce-zoom-magnifier/
5
  * Description: YITH WooCommerce Zoom Magnifier enables you to add a zoom effect to product images and a thumbnail slider for the product image gallery.
6
+ * Version: 1.2.26
7
  * Author: YITHEMES
8
  * Author URI: http://yithemes.com/
9
  * Text Domain: yith-woocommerce-zoom-magnifier
11
  *
12
  * @author Your Inspiration Themes
13
  * @package YITH WooCommerce Magnifier
14
+ * @version 1.2.26
15
  */
16
  /* Copyright 2013-2015 Your Inspiration Themes (email : plugins@yithemes.com)
17
 
76
  register_activation_hook ( __FILE__, 'yith_plugin_registration_hook' );
77
 
78
  defined ( 'YITH_YWZM_FREE_INIT' ) || define ( 'YITH_YWZM_FREE_INIT', plugin_basename ( __FILE__ ) );
79
+ defined ( 'YITH_YWZM_VERSION' ) || define ( 'YITH_YWZM_VERSION', '1.2.26' );
80
  defined ( 'YITH_YWZM_FILE' ) || define ( 'YITH_YWZM_FILE', __FILE__ );
81
  defined ( 'YITH_YWZM_DIR' ) || define ( 'YITH_YWZM_DIR', plugin_dir_path ( __FILE__ ) );
82
  defined ( 'YITH_YWZM_URL' ) || define ( 'YITH_YWZM_URL', plugins_url ( '/', __FILE__ ) );
lib/class.yith-ywzm-plugin-fw-loader.php CHANGED
@@ -101,8 +101,12 @@ if ( ! class_exists( 'YITH_YWZM_Plugin_FW_Loader' ) ) {
101
  * @author Andrea Grillo <andrea.grillo@yithemes.com>
102
  */
103
  public function plugin_fw_loader() {
104
- if ( ! defined( 'YIT_CORE_PLUGIN' ) ) {
105
- require_once( YITH_YWZM_DIR . 'plugin-fw/yit-plugin.php' );
 
 
 
 
106
  }
107
  }
108
 
101
  * @author Andrea Grillo <andrea.grillo@yithemes.com>
102
  */
103
  public function plugin_fw_loader() {
104
+ if ( !defined( 'YIT_CORE_PLUGIN' ) ) {
105
+ global $plugin_fw_data;
106
+ if ( !empty( $plugin_fw_data ) ) {
107
+ $plugin_fw_file = array_shift( $plugin_fw_data );
108
+ require_once( $plugin_fw_file );
109
+ }
110
  }
111
  }
112
 
plugin-fw/init.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Framework Name: YIT Plugin Framework
4
- * Version: 2.9.52
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.58
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,15 @@ 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 )
 
 
46
  &&
47
  ( function_exists( 'WC' ) && ! version_compare( WC()->version, '2.7', '>=' ) )
48
  && ! isset( $_COOKIE['yith_wc_2_7_notice'] )
49
  ){
50
  add_action( 'admin_notices', 'yit_fw_wc_update_message', 15 );
 
51
 
52
  if( ! function_exists( 'yit_fw_wc_update_message' ) ){
53
  function yit_fw_wc_update_message(){
@@ -61,8 +64,6 @@ if( apply_filters( 'yit_fw_wc_update_message_hook', true )
61
  }
62
  }
63
 
64
- add_action( 'admin_enqueue_scripts', 'yit_plugin_fw_dismissable_notice', 20 );
65
-
66
  if( ! function_exists( 'yit_plugin_fw_dismissable_notice' ) ){
67
  function yit_plugin_fw_dismissable_notice(){
68
  $assets_path = str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/';
@@ -76,4 +77,6 @@ if( apply_filters( 'yit_fw_wc_update_message_hook', true )
76
  wp_add_inline_script( 'jquery-cookie', $js );
77
  }
78
  }
79
- }
 
 
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(){
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/';
77
  wp_add_inline_script( 'jquery-cookie', $js );
78
  }
79
  }
80
+ }*/
81
+
82
+ /* ========================== */
plugin-fw/yit-woocommerce-compatibility.php CHANGED
@@ -8,609 +8,569 @@
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 +582,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 +629,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
+ );
190
+ }
191
+ }
192
 
193
+ if ( !function_exists( 'yit_store_changes' ) ) {
194
+ function yit_store_changes( $object, $key, $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
+
339
+ ) );
340
+ }
341
  }
342
 
343
+ if ( !function_exists( 'yit_fix_wc_deprecated_filters' ) ) {
344
+ /**
345
+ *
346
+ */
347
+ function yit_fix_wc_deprecated_filters() {
348
 
349
+ if ( !version_compare( WC()->version, '2.7.0', '<' ) ) {
350
+ return;
351
+ }
352
 
353
+ $deprecated_filters = yit_wc_deprecated_filters();
354
+ foreach ( $deprecated_filters as $old => $new ) {
355
+ add_filter( $old, 'yit_wc_deprecated_filter_mapping', 10, 100 );
356
+ }
357
+ }
 
 
 
 
 
 
358
  }
359
 
360
+ if ( !function_exists( 'yit_wc_deprecated_filter_mapping' ) ) {
361
+ /**
362
+ *
363
+ */
364
+ function yit_wc_deprecated_filter_mapping() {
365
+ $deprecated_filters = yit_wc_deprecated_filters();
 
 
 
 
 
 
366
 
367
+ $filter = current_filter();
368
+ $args = func_get_args();
369
+ $data = $args[ 0 ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
 
 
 
 
 
 
 
371
 
372
+ if ( isset( $deprecated_filters[ $filter ] ) ) {
373
+ if ( has_filter( $deprecated_filters[ $filter ] ) ) {
374
+ $data = apply_filters_ref_array( $deprecated_filters[ $filter ], $args );
375
+ }
376
+ }
377
 
378
+ return $data;
379
+ }
380
+ }
381
 
382
+ if ( !function_exists( 'yit_wc_check_post_columns' ) ) {
383
+ /**
384
+ *
385
+ */
386
+ function yit_wc_check_post_columns( $key ) {
387
+ $columns = array(
388
+ 'post_author',
389
+ 'post_date',
390
+ 'post_date_gmt',
391
+ 'post_content',
392
+ 'post_title',
393
+ 'post_excerpt',
394
+ 'post_status',
395
+ 'comment_status',
396
+ 'ping_status',
397
+ 'post_password',
398
+ 'post_name',
399
+ 'to_ping',
400
+ 'pinged',
401
+ 'post_modified',
402
+ 'post_modified_gmt',
403
+ 'post_content_filtered',
404
+ 'post_parent',
405
+ 'guid',
406
+ 'menu_order',
407
+ 'post_type',
408
+ 'post_mime_type',
409
+ 'comment_count',
410
+ );
411
 
412
+ return in_array( $key, $columns );
413
+ }
414
  }
415
 
 
 
 
 
 
 
 
 
 
416
 
417
+ /* Shortcuts for common functions */
418
 
419
+ if ( !function_exists( 'yit_get_order_id' ) ) {
420
+ /**
421
+ * Retrieve the order id
422
+ *
423
+ * @param WC_Order $order
424
+ *
425
+ * @return mixed
426
+ */
427
+ function yit_get_order_id( $order ) {
428
+ return yit_get_prop( $order, 'id' );
429
+ }
430
+ }
431
 
432
+ if ( !function_exists( 'yit_get_product_id' ) ) {
433
+ /**
434
+ * Retrieve the product id
435
+ *
436
+ * @param WC_Product $product
437
+ *
438
+ * @return mixed
439
+ */
440
+ function yit_get_product_id( $product ) {
441
+ return yit_get_prop( $product, 'id' );
442
+ }
443
+ }
444
 
445
+ if ( !function_exists( 'yit_get_base_product_id' ) ) {
446
+ /**
447
+ * New way to retrieve the $product->id as it was before WC 2.7.
448
+ *
449
+ * Retrieve the parent product id for WC_Product_Variation instances
450
+ * or the product id in the other cases.
451
+ *
452
+ * @param WC_Product $product
453
+ *
454
+ * @return mixed
455
+ */
456
+ function yit_get_base_product_id( $product ) {
457
+
458
+ return $product instanceof WC_Data && $product->is_type( 'variation' ) ?
459
+ yit_get_prop( $product, 'parent_id' ) :
460
+ yit_get_prop( $product, 'id' );
461
+ }
462
  }
463
 
464
+ if ( !function_exists( 'yit_get_display_price' ) ) {
465
+ /**
466
+ * @param WC_Product $product
467
+ * @param string $price
468
+ * @param int $qty
469
+ */
470
+ function yit_get_display_price( $product, $price = '', $qty = 1 ) {
 
 
471
 
472
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
473
 
474
+ $price = wc_get_price_to_display( $product, array( 'qty' => $qty, 'price' => $price ) );
475
+ } else {
476
 
477
+ $price = $product->get_display_price( $price, $qty );
478
+ }
479
 
480
+ return $price;
481
+ }
482
  }
483
 
484
+ if ( !function_exists( 'yit_get_price_excluding_tax' ) ) {
485
+ /**
486
+ * @param WC_Product $product
487
+ * @param int $qty
488
+ * @param string $price
489
+ *
490
+ * @return float|string
491
+ */
492
+ function yit_get_price_excluding_tax( $product, $qty = 1, $price = '' ) {
493
 
494
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
495
 
496
+ $price = wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
497
+ } else {
498
 
499
+ $price = $product->get_price_excluding_tax( $qty, $price );
500
+ }
501
 
502
+ return $price;
503
+ }
504
  }
505
 
506
+ if ( !function_exists( 'yit_get_price_including_tax' ) ) {
507
  /**
508
+ * @param WC_Product $product
509
+ * @param int $qty
510
+ * @param string $price
511
  *
512
+ * @return float|string
513
  */
514
+ function yit_get_price_including_tax( $product, $qty = 1, $price = '' ) {
 
515
 
516
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
517
+
518
+ $price = wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
519
+ } else {
520
+
521
+ $price = $product->get_price_including_tax( $qty, $price );
522
  }
523
+
524
+ return $price;
525
  }
526
  }
527
 
528
+ if ( !function_exists( 'yit_get_product_image_id' ) ) {
529
  /**
530
+ * get the attach image id
 
531
  *
532
+ * @param WC_Product $product
533
+ * @param string $context ( view/edit )
534
  */
535
+ function yit_get_product_image_id( $product, $context = 'view' ) {
 
536
 
537
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
538
+
539
+ $image_id = $product->get_image_id( $context );
540
+ } else {
541
+
542
+ $image_id = $product->get_image_id();
543
  }
544
+
545
+ return $image_id;
546
  }
547
  }
548
 
549
+ if ( !function_exists( 'yit_get_refund_amount' ) ) {
550
  /**
551
  * @param $refund \WC_Order_Refund
552
+ * @param $context string
553
  *
554
  * @return float
555
  */
556
+ function yit_get_refund_amount( $refund, $context = 'view' ) {
557
  $is_wc_data = $refund instanceof WC_Data;
558
 
559
+ if ( $is_wc_data ) {
560
+ return $refund->get_amount( $context );
561
+ } else {
562
+ return $refund->get_refund_amount();
 
563
  }
564
  }
565
  }
566
 
567
+ if ( !function_exists( 'yit_add_select2_fields' ) ) {
568
  /**
569
  * Add select 2
570
  *
571
  * @param array $args
572
  */
573
+ function yit_add_select2_fields( $args = array() ) {
574
  $default = array(
575
  'type' => 'hidden',
576
  'class' => '',
582
  'data-multiple' => false,
583
  'data-action' => '',
584
  'value' => '',
585
+ 'style' => '',
586
+ 'custom-attributes' => array()
587
  );
588
 
589
  $args = wp_parse_args( $args, $default );
590
 
591
+ $custom_attributes = array();
592
+ foreach ( $args[ 'custom-attributes' ] as $attribute => $attribute_value ) {
593
+ $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
594
+ }
595
+ $custom_attributes = implode( ' ', $custom_attributes );
596
+
597
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) :
598
+ if ( $args[ 'data-multiple' ] === true && substr( $args[ 'name' ], -2 ) != '[]' ) {
599
+ $args[ 'name' ] = $args[ 'name' ] . '[]';
600
  }
601
  ?>
602
 
603
  <select
604
+ id="<?php echo $args[ 'id' ] ?>"
605
+ class="<?php echo $args[ 'class' ] ?>"
606
+ name="<?php echo $args[ 'name' ] ?>"
607
+ data-placeholder="<?php echo $args[ 'data-placeholder' ] ?>"
608
+ data-allow_clear="<?php echo $args[ 'data-allow_clear' ] ?>"
609
+ <?php echo !empty( $args[ 'data-action' ] ) ? 'data-action="' . $args[ 'data-action' ] . '"' : ''; ?>
610
+ <?php echo !empty( $args[ 'data-multiple' ] ) ? 'multiple="multiple"' : ''; ?>
611
+ style="<?php echo $args[ 'style' ] ?>"
612
+ <?php echo $custom_attributes ?>
613
  >
614
 
615
+ <?php if ( !empty( $args[ 'value' ] ) ) {
616
+ $values = $args[ 'value' ];
617
 
618
+ if ( !is_array( $values ) ) {
619
  $values = explode( ',', $values );
620
  }
621
 
622
+ foreach ( $values as $value ): ?>
623
  <option value="<?php echo $value; ?>" <?php selected( true, true, true ) ?> >
624
+ <?php echo $args[ 'data-selected' ][ $value ]; ?>
625
  </option>
626
  <?php endforeach;
627
  }
629
  </select>
630
  <?php
631
  else :
632
+ if ( $args[ 'data-multiple' ] === false && is_array( $args[ 'data-selected' ] ) ) {
633
+ $args[ 'data-selected' ] = current($args[ 'data-selected' ]);
634
+ }
635
+
636
+ ?>
637
  <input
638
  type="hidden"
639
+ id="<?php echo $args[ 'id' ] ?>"
640
+ class="<?php echo $args[ 'class' ] ?>"
641
+ name="<?php echo $args[ 'name' ] ?>"
642
+ data-placeholder="<?php echo $args[ 'data-placeholder' ] ?>"
643
+ data-allow_clear="<?php echo $args[ 'data-allow_clear' ] ?>"
644
+ data-selected="<?php echo is_array( $args[ 'data-selected' ] ) ? esc_attr( json_encode( $args[ 'data-selected' ] ) ) : esc_attr( $args[ 'data-selected' ] ) ?>"
645
+ data-multiple="<?php echo $args[ 'data-multiple' ] === true ? 'true' : 'false' ?>"
646
+ <?php echo( !empty( $args[ 'data-action' ] ) ? 'data-action="' . $args[ 'data-action' ] . '"' : '' ) ?>
647
+ value="<?php echo $args[ 'value' ] ?>"
648
+ style="<?php echo $args[ 'style' ] ?>"
649
+ <?php echo $custom_attributes ?>
650
  />
651
  <?php
652
  endif;
653
  }
654
  }
655
 
656
+ if ( !function_exists( 'yit_product_visibility_meta' ) ) {
657
+ function yit_product_visibility_meta( $args ) {
658
+ if ( version_compare( WC()->version, '2.7.0', '<' ) ) {
659
+ $args[ 'meta_query' ] = isset( $args[ 'meta_query' ] ) ? $args[ 'meta_query' ] : array();
660
+ $args[ 'meta_query' ][] = WC()->query->visibility_meta_query();
661
+ } else {
662
+ $product_visibility_term_ids = wc_get_product_visibility_term_ids();
663
+ $args[ 'tax_query' ] = isset( $args[ 'tax_query' ] ) ? $args[ 'tax_query' ] : array();
664
+ $args[ 'tax_query' ][] = array(
665
+ 'taxonomy' => 'product_visibility',
666
+ 'field' => 'term_taxonomy_id',
667
+ 'terms' => is_search() ? $product_visibility_term_ids[ 'exclude-from-search' ] : $product_visibility_term_ids[ 'exclude-from-catalog' ],
668
+ 'operator' => 'NOT IN',
669
+ );
670
+ }
671
+
672
+ return $args;
673
+ }
674
+ }
675
+
676
+ if ( !function_exists( 'yit_datetime_to_timestamp' ) ) {
677
+
678
+ /**
679
+ *
680
+ */
681
+ function yit_datetime_to_timestamp( $date ) {
682
+
683
+ if ( version_compare( WC()->version, '2.7.0', '<' ) ) {
684
+ $date = strtotime( $date );
685
+ }
686
+
687
+ return $date;
688
+ }
689
+
690
+ }
691
+
692
 
693
  yit_fix_wc_deprecated_filters();
694
+ add_action( 'shutdown', 'yit_send_changes_to_db' );
templates/single-product/product-thumbnails-magnifier.php CHANGED
@@ -13,7 +13,8 @@ global $post, $product, $woocommerce;
13
 
14
  $enable_slider = get_option('yith_wcmg_enableslider') == 'yes' ? true : false;
15
 
16
- $attachment_ids = $product->get_gallery_attachment_ids();
 
17
 
18
  if ( ! empty( $attachment_ids ) ) array_unshift( $attachment_ids, get_post_thumbnail_id() );
19
 
@@ -62,4 +63,4 @@ if ( $attachment_ids ) {
62
  </div>
63
  <?php
64
  }
65
- ?>
13
 
14
  $enable_slider = get_option('yith_wcmg_enableslider') == 'yes' ? true : false;
15
 
16
+ $attachment_ids = version_compare(WC()->version, '3.0.0', '<') ? $product->get_gallery_attachment_ids() : $product->get_gallery_image_ids();
17
+
18
 
19
  if ( ! empty( $attachment_ids ) ) array_unshift( $attachment_ids, get_post_thumbnail_id() );
20
 
63
  </div>
64
  <?php
65
  }
66
+ ?>