WC_Compare_MetaBox

WooCommerce Compare Meta Box.

Defined (1)

The class is defined in the following location(s).

/classes/class-wc-compare-metabox.php  
  1. class WC_Compare_MetaBox  
  2. public static function compare_meta_boxes() { 
  3. global $post; 
  4. $pagename = 'product'; 
  5. add_meta_box( 'woo_compare_feature_box', __('Compare Feature Fields', 'woocommerce-compare-products' ), array('WC_Compare_MetaBox', 'woo_compare_feature_box'), $pagename, 'normal', 'high' ); 
  6.  
  7. public static function woocp_product_get_fields() { 
  8. check_ajax_referer( 'woocp-product-compare', 'security' ); 
  9. $cat_id = $_REQUEST['cat_id']; 
  10. $post_id = $_REQUEST['post_id']; 
  11. WC_Compare_MetaBox::woo_show_field_of_cat($post_id, $cat_id); 
  12. die(); 
  13.  
  14. public static function woo_compare_feature_box() { 
  15. $woocp_product_compare = wp_create_nonce("woocp-product-compare"); 
  16. global $post; 
  17. $post_id = $post->ID; 
  18. $deactivate_compare_feature = get_post_meta( $post_id, '_woo_deactivate_compare_feature', true ); 
  19. $compare_category = get_post_meta( $post_id, '_woo_compare_category', true ); 
  20. ?> 
  21. <script type="text/javascript"> 
  22. (function($) { 
  23. $(function() { 
  24. $(document).on('click', '.deactivate_compare_feature', function() { 
  25. if ($(this).is(':checked')) { 
  26. $(this).siblings(".compare_feature_activate_form").show(); 
  27. } else { 
  28. $(this).siblings(".compare_feature_activate_form").hide(); 
  29. }); 
  30. $("#compare_category").change(function() { 
  31. var cat_id = $(this).val(); 
  32. var post_id = <?php echo $post_id; ?>; 
  33. $(".compare_widget_loader").show(); 
  34. var data = { 
  35. action: 'woocp_product_get_fields',  
  36. cat_id: cat_id,  
  37. post_id: post_id,  
  38. security: '<?php echo $woocp_product_compare; ?>' 
  39. }; 
  40. $.post('<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', data, function(response) { 
  41. $(".compare_widget_loader").hide(); 
  42. $("#compare_cat_fields").html(response); 
  43. }); 
  44. }); 
  45. }); 
  46. })(jQuery); 
  47. </script> 
  48. <input id='deactivate_compare_feature' type='checkbox' value='no' <?php if ( $deactivate_compare_feature == 'no' ) echo 'checked="checked"'; else echo ''; ?> name='_woo_deactivate_compare_feature' class="deactivate_compare_feature" style="float:none; width:auto; display:inline-block;" /> 
  49. <label style="display:inline-block" for='deactivate_compare_feature' class='small'><?php _e( "Activate Compare Feature for this Product", 'woocommerce-compare-products' ); ?></label> 
  50. <div class="compare_feature_activate_form" style=" <?php if ( $deactivate_compare_feature == 'yes') { echo 'display:none;';} ?>"> 
  51. <p><label style="display:inline-block" for='compare_category' class='small'><?php _e( "Select a Compare Category for this Product", 'woocommerce-compare-products' ); ?></label> : 
  52. <select name="_woo_compare_category" id="compare_category" style="width:200px;"> 
  53. <option value="0"><?php _e('Select...', 'woocommerce-compare-products' ); ?></option> 
  54. <?php 
  55. $compare_cats = WC_Compare_Categories_Data::get_results('', 'category_order ASC'); 
  56. if (is_array($compare_cats) && count($compare_cats)>0) { 
  57. foreach ($compare_cats as $cat_data) { 
  58. if ($compare_category == $cat_data->id) { 
  59. echo '<option selected="selected" value="'.$cat_data->id.'">'.stripslashes($cat_data->category_name).'</option>'; 
  60. }else { 
  61. echo '<option value="'.$cat_data->id.'">'.stripslashes($cat_data->category_name).'</option>'; 
  62. ?> 
  63. </select> <img class="compare_widget_loader" style="display:none;" src="<?php echo WOOCP_IMAGES_URL; ?>/ajax-loader.gif" border=0 /> 
  64. </p> 
  65. <div id="compare_cat_fields"><?php WC_Compare_MetaBox::woo_show_field_of_cat($post_id, $compare_category); ?></div> 
  66. </div>  
  67. <?php 
  68.  
  69. public static function woo_show_field_of_cat($post_id=0, $cat_id=0) { 
  70. if ($cat_id > 0 && WC_Compare_Categories_Data::get_count("id='".$cat_id."'") > 0) { 
  71. ?> 
  72. <style> 
  73. .comparison_category_features_data { border: none !important;} 
  74. .comparison_category_features_data th{padding:5px 5px 5px 0px !important;} 
  75. .comparison_category_features_data td input[type="checkbox"],  
  76. .comparison_category_features_data td input[type="radio"] { 
  77. min-width: 16px !important; 
  78. @media screen and ( max-width: 782px ) { 
  79. .comparison_category_features_data textarea, .comparison_category_features_data input[type="text"], .comparison_category_features_data input[type="email"], .comparison_category_features_data input[type="number"], .comparison_category_features_data input[type="password"], .comparison_category_features_data select { 
  80. width: 100% !important;  
  81. </style> 
  82. <table cellspacing="0" cellpadding="5" style="width: 100%;" class="form-table comparison_category_features_data"> 
  83. <tbody> 
  84. <?php 
  85. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$cat_id."'", 'cf.field_order ASC'); 
  86. if (is_array($compare_fields) && count($compare_fields)>0) { 
  87.  
  88. foreach ($compare_fields as $field_data) { 
  89. ?> 
  90. <tr class="form-field"> 
  91. <th valign="top" scope="row"><label style="display:inline-block" for="<?php echo $field_data->field_key; ?>"><strong><?php echo stripslashes($field_data->field_name); ?> : </strong></label><?php if (trim($field_data->field_unit) != '') { ?><br />(<?php echo trim(stripslashes($field_data->field_unit)); ?>)<?php } ?></th> 
  92. <td> 
  93. <?php 
  94. $field_value = get_post_meta( $post_id, '_woo_compare_'.$field_data->field_key, true ); 
  95. switch ($field_data->field_type) { 
  96. case "text-area": 
  97. echo '<textarea style="width:400px" name="_woo_compare_'.$field_data->field_key.'" id="'.$field_data->field_key.'">'.$field_value.'</textarea>'; 
  98. break; 
  99.  
  100. case "checkbox": 
  101. $default_value = nl2br($field_data->default_value); 
  102. $field_option = explode('<br />', $default_value); 
  103. if (is_serialized($field_value)) $field_value = maybe_unserialize($field_value); 
  104. if (!is_array($field_value)) $field_value = array(); 
  105. if (is_array($field_option) && count($field_option) > 0) { 
  106. foreach ($field_option as $option_value) { 
  107. $option_value = trim(stripslashes($option_value)); 
  108. if (in_array($option_value, $field_value)) { 
  109. echo '<input type="checkbox" name="_woo_compare_'.$field_data->field_key.'[]" value="'.esc_attr($option_value).'" checked="checked" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  110. }else { 
  111. echo '<input type="checkbox" name="_woo_compare_'.$field_data->field_key.'[]" value="'.esc_attr($option_value).'" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  112. break; 
  113.  
  114. case "radio": 
  115. $default_value = nl2br($field_data->default_value); 
  116. $field_option = explode('<br />', $default_value); 
  117. if (is_array($field_option) && count($field_option) > 0) { 
  118. foreach ($field_option as $option_value) { 
  119. $option_value = trim(stripslashes($option_value)); 
  120. if ($option_value == $field_value) { 
  121. echo '<input type="radio" name="_woo_compare_'.$field_data->field_key.'" value="'.esc_attr($option_value).'" checked="checked" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  122. }else { 
  123. echo '<input type="radio" name="_woo_compare_'.$field_data->field_key.'" value="'.esc_attr($option_value).'" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  124. break; 
  125.  
  126. case "drop-down": 
  127. $default_value = nl2br($field_data->default_value); 
  128. $field_option = explode('<br />', $default_value); 
  129. echo '<select name="_woo_compare_'.$field_data->field_key.'" id="'.$field_data->field_key.'" style="width:400px">'; 
  130. echo '<option value="">'.__( "Select value", 'woocommerce-compare-products' ).'</option>'; 
  131. if (is_array($field_option) && count($field_option) > 0) { 
  132. foreach ($field_option as $option_value) { 
  133. $option_value = trim(stripslashes($option_value)); 
  134. if ($option_value == $field_value) { 
  135. echo '<option value="'.esc_attr($option_value).'" selected="selected">'.esc_attr( $option_value ).'</option>'; 
  136. }else { 
  137. echo '<option value="'.esc_attr($option_value).'">'.esc_attr( $option_value ).'</option>'; 
  138. echo '</select>'; 
  139. break; 
  140.  
  141. case "multi-select": 
  142. $default_value = nl2br($field_data->default_value); 
  143. $field_option = explode('<br />', $default_value); 
  144. if (is_serialized($field_value)) $field_value = maybe_unserialize($field_value); 
  145. if (!is_array($field_value)) $field_value = array(); 
  146. echo '<select multiple="multiple" name="_woo_compare_'.$field_data->field_key.'[]" id="'.$field_data->field_key.'" style="width:400px">'; 
  147. if (is_array($field_option) && count($field_option) > 0) { 
  148. foreach ($field_option as $option_value) { 
  149. $option_value = trim(stripslashes($option_value)); 
  150. if (in_array($option_value, $field_value)) { 
  151. echo '<option value="'.esc_attr($option_value).'" selected="selected">'.esc_attr( $option_value ).'</option>'; 
  152. }else { 
  153. echo '<option value="'.esc_attr($option_value).'">'.esc_attr( $option_value ).'</option>'; 
  154. echo '</select>'; 
  155. break; 
  156.  
  157. default: 
  158. echo '<input style="width:400px" type="text" name="_woo_compare_'.$field_data->field_key.'" id="'.$field_data->field_key.'" value="'.esc_attr( $field_value ).'" />'; 
  159. break; 
  160. ?> 
  161. </td> 
  162. </tr> 
  163. <?php 
  164. }else { 
  165. ?> 
  166. <tr><td><i style="text-decoration:blink"><?php _e('There are no Features created for this category, please add some.', 'woocommerce-compare-products' ); ?> <a href="admin.php?page=woo-compare-features" target="_blank"><?php _e('This page', 'woocommerce-compare-products' ); ?></a></i></td></tr> 
  167. <?php 
  168. ?> 
  169. </tbody> 
  170. </table> 
  171. <?php 
  172.  
  173. public static function woo_variations_compare_feature_box($post_id) { 
  174. $deactivate_compare_feature = get_post_meta( $post_id, '_woo_deactivate_compare_feature', true ); 
  175. $compare_category = get_post_meta( $post_id, '_woo_compare_category', true ); 
  176. ?> 
  177. <div> 
  178. <input id='deactivate_compare_feature_<?php echo $post_id; ?>' type='checkbox' value='no' <?php if ( $deactivate_compare_feature == 'no' ) echo 'checked="checked"'; else echo ''; ?> class="deactivate_compare_feature" name='variable_woo_deactivate_compare_feature[<?php echo $post_id; ?>]' style="float:none; width:auto; display:inline-block;" /> 
  179. <label style="display:inline-block" for='deactivate_compare_feature_<?php echo $post_id; ?>' class='small'><?php _e( "Activate Compare Feature for this Product", 'woocommerce-compare-products' ); ?></label> 
  180. <div class="compare_feature_activate_form" style=" <?php if ( $deactivate_compare_feature == 'yes') { echo 'display:none;';} ?>"> 
  181. <p><label style="display:inline-block" for='variable_woo_compare_category_<?php echo $post_id; ?>' class='small'><?php _e( "Select a Compare Category for this Product", 'woocommerce-compare-products' ); ?></label> : 
  182. <select name="variable_woo_compare_category[<?php echo $post_id; ?>]" class="variable_compare_category" id="variable_woo_compare_category_<?php echo $post_id; ?>" style="width:200px;" rel="<?php echo $post_id; ?>"> 
  183. <option value="0"><?php _e('Select...', 'woocommerce-compare-products' ); ?></option> 
  184. <?php 
  185. $compare_cats = WC_Compare_Categories_Data::get_results('', 'category_order ASC'); 
  186. if (is_array($compare_cats) && count($compare_cats)>0) { 
  187. foreach ($compare_cats as $cat_data) { 
  188. if ($compare_category == $cat_data->id) { 
  189. echo '<option selected="selected" value="'.$cat_data->id.'">'.stripslashes($cat_data->category_name).'</option>'; 
  190. }else { 
  191. echo '<option value="'.$cat_data->id.'">'.stripslashes($cat_data->category_name).'</option>'; 
  192. ?> 
  193. </select> <img id="variable_compare_widget_loader_<?php echo $post_id; ?>" style="display:none;" src="<?php echo WOOCP_IMAGES_URL; ?>/ajax-loader.gif" border=0 /> 
  194. </p> 
  195. <div id="variable_compare_cat_fields_<?php echo $post_id; ?>"><?php WC_Compare_MetaBox::woo_variation_show_field_of_cat($post_id, $compare_category); ?></div> 
  196. </div> 
  197. </div> 
  198. <?php 
  199.  
  200. public static function woo_variation_show_field_of_cat($post_id=0, $cat_id=0) { 
  201. if ($cat_id > 0 && WC_Compare_Categories_Data::get_count("id='".$cat_id."'") > 0) { 
  202. ?> 
  203. <style> 
  204. .comparison_category_features_data { border: none !important;} 
  205. .comparison_category_features_data th{padding:5px 5px 5px 0px !important;} 
  206. .comparison_category_features_data td input[type="checkbox"],  
  207. .comparison_category_features_data td input[type="radio"] { 
  208. min-width: 16px !important; 
  209. </style> 
  210. <table cellspacing="0" cellpadding="5" style="width: 100%;" class="form-table comparison_category_features_data"> 
  211. <tbody> 
  212. <?php 
  213. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$cat_id."'", 'cf.field_order ASC'); 
  214. if (is_array($compare_fields) && count($compare_fields)>0) { 
  215.  
  216. foreach ($compare_fields as $field_data) { 
  217. ?> 
  218. <tr class="form-field"> 
  219. <th valign="top" scope="row"><label style="display:inline-block" for="<?php echo $field_data->field_key; ?>_<?php echo $post_id; ?>"><strong><?php echo stripslashes($field_data->field_name); ?> : </strong></label><?php if (trim($field_data->field_unit) != '') { ?><br /> (<?php echo trim(stripslashes($field_data->field_unit)); ?>)<?php } ?></th> 
  220. <td> 
  221. <?php 
  222. $field_value = get_post_meta( $post_id, '_woo_compare_'.$field_data->field_key, true ); 
  223. switch ($field_data->field_type) { 
  224. case "text-area": 
  225. echo '<textarea style="width:400px" name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.']" id="'.$field_data->field_key.'_'.$post_id.'">'.$field_value.'</textarea>'; 
  226. break; 
  227.  
  228. case "checkbox": 
  229. $default_value = nl2br($field_data->default_value); 
  230. $field_option = explode('<br />', $default_value); 
  231. if (is_serialized($field_value)) $field_value = maybe_unserialize($field_value); 
  232. if (!is_array($field_value)) $field_value = array(); 
  233. if (is_array($field_option) && count($field_option) > 0) { 
  234. foreach ($field_option as $option_value) { 
  235. $option_value = trim(stripslashes($option_value)); 
  236. if (in_array($option_value, $field_value)) { 
  237. echo '<input type="checkbox" name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.'][]" value="'.esc_attr($option_value).'" checked="checked" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  238. }else { 
  239. echo '<input type="checkbox" name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.'][]" value="'.esc_attr($option_value).'" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  240. break; 
  241.  
  242. case "radio": 
  243. $default_value = nl2br($field_data->default_value); 
  244. $field_option = explode('<br />', $default_value); 
  245. if (is_array($field_option) && count($field_option) > 0) { 
  246. foreach ($field_option as $option_value) { 
  247. $option_value = trim(stripslashes($option_value)); 
  248. if ($option_value == $field_value) { 
  249. echo '<input type="radio" name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.']" value="'.esc_attr($option_value).'" checked="checked" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  250. }else { 
  251. echo '<input type="radio" name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.']" value="'.esc_attr($option_value).'" style="float:none; width:auto; display:inline-block;" /> '.esc_attr( $option_value ).'    '; 
  252. break; 
  253.  
  254. case "drop-down": 
  255. $default_value = nl2br($field_data->default_value); 
  256. $field_option = explode('<br />', $default_value); 
  257. echo '<select name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.']" id="'.$field_data->field_key.'_'.$post_id.'" style="width:400px">'; 
  258. echo '<option value="">'.__( "Select value", 'woocommerce-compare-products' ).'</option>'; 
  259. if (is_array($field_option) && count($field_option) > 0) { 
  260. foreach ($field_option as $option_value) { 
  261. $option_value = trim(stripslashes($option_value)); 
  262. if ($option_value == $field_value) { 
  263. echo '<option value="'.esc_attr($option_value).'" selected="selected">'.esc_attr( $option_value ).'</option>'; 
  264. }else { 
  265. echo '<option value="'.esc_attr($option_value).'">'.esc_attr( $option_value ).'</option>'; 
  266. echo '</select>'; 
  267. break; 
  268.  
  269. case "multi-select": 
  270. $default_value = nl2br($field_data->default_value); 
  271. $field_option = explode('<br />', $default_value); 
  272. if (is_serialized($field_value)) $field_value = maybe_unserialize($field_value); 
  273. if (!is_array($field_value)) $field_value = array(); 
  274. echo '<select multiple="multiple" name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.'][]" id="'.$field_data->field_key.'_'.$post_id.'" style="width:400px">'; 
  275. if (is_array($field_option) && count($field_option) > 0) { 
  276. foreach ($field_option as $option_value) { 
  277. $option_value = trim(stripslashes($option_value)); 
  278. if (in_array($option_value, $field_value)) { 
  279. echo '<option value="'.esc_attr($option_value).'" selected="selected">'.esc_attr( $option_value ).'</option>'; 
  280. }else { 
  281. echo '<option value="'.esc_attr($option_value).'">'.esc_attr( $option_value ).'</option>'; 
  282. echo '</select>'; 
  283. break; 
  284.  
  285. default: 
  286. echo '<input style="width:400px" type="text" name="variable_woo_compare_'.$field_data->field_key.'['.$post_id.']" id="'.$field_data->field_key.'_'.$post_id.'" value="'.esc_attr( $field_value ).'" />'; 
  287. break; 
  288. ?> 
  289. </td> 
  290. </tr> 
  291. <?php 
  292. }else { 
  293. ?> 
  294. <tr><td><i style="text-decoration:blink"><?php _e('There are no Features created for this category, please add some.', 'woocommerce-compare-products' ); ?> <a href="admin.php?page=woo-compare-features" target="_blank"><?php _e('This page', 'woocommerce-compare-products' ); ?></a></i></td></tr> 
  295. <?php 
  296. ?> 
  297. </tbody> 
  298. </table> 
  299. <?php 
  300.  
  301. public static function woocp_get_variation_compare() { 
  302. check_ajax_referer( 'woocp-variable-compare', 'security' ); 
  303. $variation_id = $_REQUEST['variation_id']; 
  304. echo WC_Compare_MetaBox::woo_variations_compare_feature_box($variation_id); 
  305. die(); 
  306.  
  307. public static function woocp_variation_get_fields() { 
  308. check_ajax_referer( 'woocp-variable-compare', 'security' ); 
  309. $cat_id = $_REQUEST['cat_id']; 
  310. $post_id = $_REQUEST['post_id']; 
  311. WC_Compare_MetaBox::woo_variation_show_field_of_cat($post_id, $cat_id); 
  312. die(); 
  313.  
  314. public static function variable_compare_meta_boxes( $loop, $variation_data, $variation ) { 
  315. self::woo_variations_compare_feature_box( $variation->ID ); 
  316.  
  317. public static function admin_include_variation_compare_scripts() { 
  318. if ( version_compare( WC_VERSION, '2.4.0', '<' ) ) { 
  319. self::variable_compare_meta_boxes_scripts_old(); 
  320. } else { 
  321. self::variable_compare_meta_boxes_scripts(); 
  322.  
  323. public static function variable_compare_meta_boxes_scripts() { 
  324. global $post; 
  325. $post_status = get_post_status($post->ID); 
  326. $post_type = get_post_type($post->ID); 
  327. if ($post_type == 'product' && $post_status != false) { 
  328. $woocp_variable_compare = wp_create_nonce("woocp-variable-compare"); 
  329.  
  330. ob_start(); 
  331. ?> 
  332. jQuery(function() { 
  333.  
  334. jQuery(document).on("change", ".variable_compare_category", function() { 
  335. var cat_id = jQuery(this).val(); 
  336. var post_id = jQuery(this).attr("rel"); 
  337. jQuery("#variable_compare_widget_loader_"+post_id).show(); 
  338. var data = { 
  339. action: 'woocp_variation_get_fields',  
  340. cat_id: cat_id,  
  341. post_id: post_id,  
  342. security: '<?php echo $woocp_variable_compare; ?>' 
  343. }; 
  344. jQuery.post('<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', data, function(response) { 
  345. jQuery("#variable_compare_widget_loader_"+post_id).hide(); 
  346. jQuery("#variable_compare_cat_fields_"+post_id).html(response); 
  347. }); 
  348. }); 
  349. }); 
  350.  
  351. <?php 
  352. $javascript = ob_get_clean(); 
  353.  
  354. wc_enqueue_js( $javascript ); 
  355.  
  356. public static function variable_compare_meta_boxes_scripts_old() { 
  357. global $post; 
  358. $current_db_version = get_option( 'woocommerce_db_version', null ); 
  359. $post_status = get_post_status($post->ID); 
  360. $post_type = get_post_type($post->ID); 
  361. if ($post_type == 'product' && $post_status != false) { 
  362. $woocp_variable_compare = wp_create_nonce("woocp-variable-compare"); 
  363. $attributes = (array) maybe_unserialize( get_post_meta($post->ID, '_product_attributes', true) ); 
  364.  
  365. // See if any are set 
  366. $variation_attribute_found = false; 
  367. if ($attributes) foreach ($attributes as $attribute) { 
  368. if (isset($attribute['is_variation'])) : 
  369. $variation_attribute_found = true; 
  370. break; 
  371. endif; 
  372. if ($variation_attribute_found) { 
  373. if ( version_compare( $current_db_version, '2.1.0', '<' ) && null !== $current_db_version ) { 
  374. $colspan = 7; 
  375. } else { 
  376. $colspan = 3; 
  377. $args = array( 
  378. 'post_type' => 'product_variation',  
  379. 'post_status' => array('private', 'publish'),  
  380. 'numberposts' => -1,  
  381. 'orderby' => 'id',  
  382. 'order' => 'asc',  
  383. 'post_parent' => $post->ID 
  384. ); 
  385. $variations = get_posts($args); 
  386. $loop = 0; 
  387. ob_start(); 
  388. ?> 
  389. jQuery(function() { 
  390. <?php 
  391. if ($variations && count($variations) > 0) {?> 
  392. jQuery('#variable_product_options .woocommerce_variation').each(function() { 
  393. var current_variation = jQuery(this); 
  394. if(current_variation.hasClass('have_compare_feature') == false) { 
  395. var variation_id = jQuery(this).find('.remove_variation').attr('rel'); 
  396. var data = { 
  397. action: 'woocp_get_variation_compare',  
  398. variation_id: variation_id,  
  399. security: '<?php echo $woocp_variable_compare; ?>' 
  400. }; 
  401. jQuery.post('<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', data, function(response) { 
  402. current_variation.find('table.woocommerce_variable_attributes').append('<tr><td colspan="<?php echo $colspan; ?>">'+response+'</td></tr>'); 
  403. }); 
  404. current_variation.addClass('have_compare_feature'); 
  405. }); 
  406. <?php } ?> 
  407. jQuery('#variable_product_options').on('click', 'button.add_variation', function() { 
  408. setTimeout(function() { 
  409. jQuery('#variable_product_options .woocommerce_variation').each(function() { 
  410. var current_variation = jQuery(this); 
  411. if(current_variation.hasClass('have_compare_feature') == false) { 
  412. var variation_id = jQuery(this).find('.remove_variation').attr('rel'); 
  413. var data = { 
  414. action: 'woocp_get_variation_compare',  
  415. variation_id: variation_id,  
  416. security: '<?php echo $woocp_variable_compare; ?>' 
  417. }; 
  418. jQuery.post('<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', data, function(response) { 
  419. current_variation.find('table.woocommerce_variable_attributes').append('<tr><td colspan="<?php echo $colspan; ?>">'+response+'</td></tr>'); 
  420. }); 
  421. current_variation.addClass('have_compare_feature'); 
  422. }); 
  423. }, 3000); 
  424. }); 
  425. jQuery('#variable_product_options').on('click', 'button.link_all_variations', function() { 
  426. setTimeout(function() { 
  427. jQuery('#variable_product_options .woocommerce_variation').each(function() { 
  428. var current_variation = jQuery(this); 
  429. if(current_variation.hasClass('have_compare_feature') == false) { 
  430. var variation_id = jQuery(this).find('.remove_variation').attr('rel'); 
  431. var data = { 
  432. action: 'woocp_get_variation_compare',  
  433. variation_id: variation_id,  
  434. security: '<?php echo $woocp_variable_compare; ?>' 
  435. }; 
  436. jQuery.post('<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', data, function(response) { 
  437. current_variation.find('table.woocommerce_variable_attributes').append('<tr><td colspan="<?php echo $colspan; ?>">'+response+'</td></tr>'); 
  438. }); 
  439. current_variation.addClass('have_compare_feature'); 
  440. }); 
  441. }, 5000); 
  442. }); 
  443. jQuery(document).on("change", ".variable_compare_category", function() { 
  444. var cat_id = jQuery(this).val(); 
  445. var post_id = jQuery(this).attr("rel"); 
  446. jQuery("#variable_compare_widget_loader_"+post_id).show(); 
  447. var data = { 
  448. action: 'woocp_variation_get_fields',  
  449. cat_id: cat_id,  
  450. post_id: post_id,  
  451. security: '<?php echo $woocp_variable_compare; ?>' 
  452. }; 
  453. jQuery.post('<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', data, function(response) { 
  454. jQuery("#variable_compare_widget_loader_"+post_id).hide(); 
  455. jQuery("#variable_compare_cat_fields_"+post_id).html(response); 
  456. }); 
  457. }); 
  458. }); 
  459.  
  460. <?php 
  461. $javascript = ob_get_clean(); 
  462. if ( version_compare( $current_db_version, '2.1.0', '<' ) && null !== $current_db_version ) { 
  463. global $woocommerce; 
  464. $woocommerce->add_inline_js( $javascript ); 
  465. } else { 
  466. wc_enqueue_js( $javascript ); 
  467.  
  468. public static function save_compare_meta_boxes($post_id) { 
  469. $post_status = get_post_status($post_id); 
  470. $post_type = get_post_type($post_id); 
  471. if ($post_type == 'product' && $post_status != false) { 
  472. if (isset($_REQUEST['_woo_deactivate_compare_feature']) && $_REQUEST['_woo_deactivate_compare_feature'] == 'no') { 
  473. update_post_meta($post_id, '_woo_deactivate_compare_feature', 'no'); 
  474. }else { 
  475. update_post_meta($post_id, '_woo_deactivate_compare_feature', 'yes'); 
  476.  
  477. $compare_category = 0; 
  478. if ( isset($_REQUEST['_woo_compare_category']) ) { 
  479. $compare_category = $_REQUEST['_woo_compare_category']; 
  480. update_post_meta($post_id, '_woo_compare_category', $compare_category); 
  481.  
  482. $category_data = WC_Compare_Categories_Data::get_row($compare_category); 
  483. if ( $category_data != NULL ) update_post_meta($post_id, '_woo_compare_category_name', stripslashes($category_data->category_name)); 
  484.  
  485. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$compare_category."'", 'cf.field_order ASC'); 
  486. if (is_array($compare_fields) && count($compare_fields)>0) { 
  487. foreach ($compare_fields as $field_data) { 
  488. if ( isset( $_REQUEST['_woo_compare_'.$field_data->field_key] ) ) 
  489. update_post_meta($post_id, '_woo_compare_'.$field_data->field_key, $_REQUEST['_woo_compare_'.$field_data->field_key]); 
  490.  
  491. if (isset($_REQUEST['variable_post_id'])) { 
  492. $variable_ids = $_REQUEST['variable_post_id']; 
  493. foreach ($variable_ids as $variation_id) { 
  494. $post_type = get_post_type($variation_id); 
  495. if ($post_type == 'product_variation') { 
  496. if ( isset( $_REQUEST['variable_woo_deactivate_compare_feature'][$variation_id] ) && $_REQUEST['variable_woo_deactivate_compare_feature'][$variation_id] == 'no' ) { 
  497. update_post_meta($variation_id, '_woo_deactivate_compare_feature', 'no'); 
  498. }else { 
  499. update_post_meta($variation_id, '_woo_deactivate_compare_feature', 'yes'); 
  500.  
  501. $variation_compare_category = 0; 
  502. if ( isset($_REQUEST['variable_woo_compare_category'][$variation_id]) ) { 
  503. $variation_compare_category = $_REQUEST['variable_woo_compare_category'][$variation_id]; 
  504. update_post_meta($variation_id, '_woo_compare_category', $variation_compare_category); 
  505.  
  506. $variation_category_data = WC_Compare_Categories_Data::get_row($variation_compare_category); 
  507. if ( $variation_category_data != NULL ) update_post_meta($variation_id, '_woo_compare_category_name', stripslashes($variation_category_data->category_name)); 
  508.  
  509. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$variation_compare_category."'", 'cf.field_order ASC'); 
  510. if (is_array($compare_fields) && count($compare_fields)>0) { 
  511. foreach ($compare_fields as $field_data) { 
  512. if ( isset( $_REQUEST['variable_woo_compare_'.$field_data->field_key][$variation_id] ) ) 
  513. update_post_meta($variation_id, '_woo_compare_'.$field_data->field_key, $_REQUEST['variable_woo_compare_'.$field_data->field_key][$variation_id]); 
  514.  
  515. public static function save_product_variation( $variation_id, $i ) { 
  516. if ( isset( $_POST['variable_woo_deactivate_compare_feature'][$variation_id] ) && $_POST['variable_woo_deactivate_compare_feature'][$variation_id] == 'no' ) { 
  517. update_post_meta($variation_id, '_woo_deactivate_compare_feature', 'no'); 
  518. }else { 
  519. update_post_meta($variation_id, '_woo_deactivate_compare_feature', 'yes'); 
  520.  
  521. $variation_compare_category = 0; 
  522. if ( isset($_POST['variable_woo_compare_category'][$variation_id]) ) { 
  523. $variation_compare_category = $_POST['variable_woo_compare_category'][$variation_id]; 
  524. update_post_meta($variation_id, '_woo_compare_category', $variation_compare_category); 
  525.  
  526. $variation_category_data = WC_Compare_Categories_Data::get_row($variation_compare_category); 
  527. if ( $variation_category_data != NULL ) update_post_meta($variation_id, '_woo_compare_category_name', stripslashes($variation_category_data->category_name)); 
  528.  
  529. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$variation_compare_category."'", 'cf.field_order ASC'); 
  530. if (is_array($compare_fields) && count($compare_fields)>0) { 
  531. foreach ($compare_fields as $field_data) { 
  532. if ( isset( $_POST['variable_woo_compare_'.$field_data->field_key][$variation_id] ) ) 
  533. update_post_meta($variation_id, '_woo_compare_'.$field_data->field_key, $_POST['variable_woo_compare_'.$field_data->field_key][$variation_id]);