WC_Compare_Hook_Filter

WooCommerce Compare Hook Filter.

Defined (1)

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

/classes/class-wc-compare-filter.php  
  1. class WC_Compare_Hook_Filter 
  2. public static function register_admin_screen () { 
  3.  
  4. $product_comparison = add_menu_page( __('Product Comparison', 'woocommerce-compare-products' ), __('WC Compare', 'woocommerce-compare-products' ), 'manage_options', 'woo-compare-features', array( 'WC_Compare_Features_Panel', 'admin_screen' ), null, '55.222'); 
  5.  
  6. $compare_features = add_submenu_page('woo-compare-features', __( 'Compare Category & Feature', 'woocommerce-compare-products' ), __( 'Category & Feature', 'woocommerce-compare-products' ), 'manage_options', 'woo-compare-features', array( 'WC_Compare_Features_Panel', 'admin_screen' ) ); 
  7.  
  8. $compare_products = add_submenu_page('woo-compare-features', __( 'Compare Products Manager', 'woocommerce-compare-products' ), __( 'Product Manager', 'woocommerce-compare-products' ), 'manage_options', 'woo-compare-products', array( 'WC_Compare_Products_Class', 'woocp_products_manager' ) ); 
  9.  
  10. } // End register_admin_screen() 
  11.  
  12. public static function template_loader( $template ) { 
  13. global $product_compare_id; 
  14. global $post; 
  15. $current_db_version = get_option( 'woocommerce_db_version', null ); 
  16.  
  17. if ( is_object( $post ) && $product_compare_id == $post->ID ) { 
  18.  
  19. if ( version_compare( $current_db_version, '2.1.0', '<' ) && null !== $current_db_version ) { 
  20. $file = 'product-compare-old.php'; 
  21. } else { 
  22. $file = 'product-compare.php'; 
  23. $find[] = $file; 
  24. $find[] = apply_filters( 'woocommerce_template_url', 'woocommerce/' ) . $file; 
  25.  
  26. $template = locate_template( $find ); 
  27. if ( ! $template ) $template = WOOCP_FILE_PATH . '/templates/' . $file; 
  28.  
  29.  
  30. return $template; 
  31.  
  32. public static function nocache_ours_page() { 
  33. global $product_compare_id; 
  34.  
  35. $woocp_page_uris = array(); 
  36. // Exclude querystring when using page ID 
  37. $woocp_page_uris[] = 'p=' . $product_compare_id; 
  38. $woocp_page_uris[] = 'page_id=' . $product_compare_id; 
  39.  
  40. // Exclude permalinks 
  41. $comparision_page = get_post( $product_compare_id ); 
  42.  
  43. if ( ! is_null( $comparision_page ) ) 
  44. $woocp_page_uris[] = '/' . $comparision_page->post_name; 
  45.  
  46. if ( is_array( $woocp_page_uris ) ) { 
  47. foreach( $woocp_page_uris as $uri ) { 
  48. if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { 
  49. if ( ! defined( 'DONOTCACHEPAGE' ) ) 
  50. define( "DONOTCACHEPAGE", "true" ); 
  51.  
  52. if ( ! defined( 'DONOTCACHEOBJECT' ) ) 
  53. define( "DONOTCACHEOBJECT", "true" ); 
  54.  
  55. if ( ! defined( 'DONOTCACHEDB' ) ) 
  56. define( "DONOTCACHEDB", "true" ); 
  57.  
  58. nocache_headers(); 
  59.  
  60. public static function add_google_fonts() { 
  61. global $wc_compare_fonts_face; 
  62. global $woo_compare_product_page_settings; 
  63. $google_fonts = array(  
  64. $woo_compare_product_page_settings['product_compare_link_font']['face'],  
  65. $woo_compare_product_page_settings['product_compare_button_font']['face'],  
  66. $woo_compare_product_page_settings['product_view_compare_link_font']['face'],  
  67. $woo_compare_product_page_settings['product_view_button_font']['face'],  
  68. ); 
  69.  
  70. $google_fonts = apply_filters( 'wc_compare_google_fonts', $google_fonts ); 
  71.  
  72. $wc_compare_fonts_face->generate_google_webfonts( $google_fonts ); 
  73.  
  74. public static function add_google_fonts_comparison_page() { 
  75. global $wc_compare_fonts_face; 
  76. global $woo_compare_comparison_page_global_settings; 
  77. $google_fonts = array(  
  78. $woo_compare_comparison_page_global_settings['no_product_message_font']['face'],  
  79. ); 
  80.  
  81. $google_fonts = apply_filters( 'wc_comparison_page_google_fonts', $google_fonts ); 
  82.  
  83. $wc_compare_fonts_face->generate_google_webfonts( $google_fonts ); 
  84.  
  85. public static function include_customized_style() { 
  86. include( WOOCP_DIR. '/templates/customized_style.php' ); 
  87.  
  88. public static function woocp_shop_add_compare_button($template_name, $template_path, $located) { 
  89. global $post; 
  90. global $product; 
  91. global $woo_compare_grid_view_settings; 
  92. global $woo_compare_comparison_page_global_settings; 
  93. global $product_compare_id; 
  94. extract($woo_compare_grid_view_settings); 
  95. if ($template_name == 'loop/add-to-cart.php') { 
  96. $product_id = $product->get_id(); 
  97. if (($post->post_type == 'product' || $post->post_type == 'product_variation') && WC_Compare_Functions::check_product_activate_compare($product_id) && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  98. $compare_grid_view_custom_class = ''; 
  99. $compare_grid_view_text = __('Compare This', 'woocommerce-compare-products' ); 
  100. $compare_grid_view_class = 'woo_bt_compare_this_button'; 
  101.  
  102. $view_compare_html = ''; 
  103.  
  104. $compare_html = '<div class="woo_grid_compare_button_container"><a class="woo_bt_compare_this '.$compare_grid_view_class.' '.$compare_grid_view_custom_class.'" id="woo_bt_compare_this_'.$product_id.'">'.$compare_grid_view_text.'</a>' . $view_compare_html . '<input type="hidden" id="input_woo_bt_compare_this_'.$product_id.'" name="product_compare_'.$product_id.'" value="'.$product_id.'" /></div>'; 
  105. echo $compare_html; 
  106.  
  107. public static function woocp_shop_add_compare_button_below_cart() { 
  108. global $post; 
  109. global $product; 
  110. global $woo_compare_grid_view_settings; 
  111. global $woo_compare_comparison_page_global_settings; 
  112. global $product_compare_id; 
  113.  
  114. if ( $woo_compare_grid_view_settings['disable_grid_view_compare'] == 1 || $woo_compare_grid_view_settings['grid_view_button_position'] == 'above' ) return; 
  115.  
  116. extract($woo_compare_grid_view_settings); 
  117. $product_id = $product->get_id(); 
  118. if (($post->post_type == 'product' || $post->post_type == 'product_variation') && WC_Compare_Functions::check_product_activate_compare($product_id) && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  119. $compare_grid_view_custom_class = ''; 
  120. $compare_grid_view_text = __('Compare This', 'woocommerce-compare-products' ); 
  121. $compare_grid_view_class = 'woo_bt_compare_this_button'; 
  122.  
  123. $view_compare_html = ''; 
  124.  
  125. $compare_html = '<div class="woo_grid_compare_button_container"><a class="woo_bt_compare_this '.$compare_grid_view_class.' '.$compare_grid_view_custom_class.'" id="woo_bt_compare_this_'.$product_id.'">'.$compare_grid_view_text.'</a>' . $view_compare_html . '<input type="hidden" id="input_woo_bt_compare_this_'.$product_id.'" name="product_compare_'.$product_id.'" value="'.$product_id.'" /></div>'; 
  126. echo $compare_html; 
  127.  
  128. public static function woocp_details_add_compare_button() { 
  129. global $post; 
  130. global $product; 
  131. global $woo_compare_product_page_settings; 
  132. global $woo_compare_comparison_page_global_settings; 
  133. global $product_compare_id; 
  134. $product_id = $product->get_id(); 
  135. if (($post->post_type == 'product' || $post->post_type == 'product_variation') && WC_Compare_Functions::check_product_activate_compare($product_id) && $woo_compare_product_page_settings['auto_add'] == 'yes' && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  136.  
  137. $widget_compare_popup_view_button = ''; 
  138. if ( $woo_compare_comparison_page_global_settings['open_compare_type'] != 'new_page' ) $widget_compare_popup_view_button = 'woo_bt_view_compare_popup'; 
  139.  
  140. $product_compare_custom_class = ''; 
  141. $product_compare_text = $woo_compare_product_page_settings['product_compare_button_text']; 
  142. $product_compare_class = 'woo_bt_compare_this_button'; 
  143. if ($woo_compare_product_page_settings['product_compare_button_type'] == 'link') { 
  144. $product_compare_custom_class = ''; 
  145. $product_compare_text = $woo_compare_product_page_settings['product_compare_link_text']; 
  146. $product_compare_class = 'woo_bt_compare_this_link'; 
  147.  
  148. $view_compare_html = ''; 
  149. if ($woo_compare_product_page_settings['disable_product_view_compare'] == 0) { 
  150. $product_view_compare_custom_class = ''; 
  151. $product_view_compare_text = $woo_compare_product_page_settings['product_view_compare_link_text']; 
  152. $product_view_compare_class = 'woo_bt_view_compare_link'; 
  153. if ($woo_compare_product_page_settings['product_view_compare_button_type'] == 'button') { 
  154. $product_view_compare_custom_class = ''; 
  155. $product_view_compare_text = $woo_compare_product_page_settings['product_view_compare_button_text']; 
  156. $product_view_compare_class = 'woo_bt_view_compare_button'; 
  157. $product_compare_page = get_permalink($product_compare_id); 
  158. if ($woo_compare_comparison_page_global_settings['open_compare_type'] != 'new_page') { 
  159. $product_compare_page = '#'; 
  160. $view_compare_html = '<div style="clear:both;"></div><a class="woo_bt_view_compare '.$widget_compare_popup_view_button.' '.$product_view_compare_class.' '.$product_view_compare_custom_class.'" href="'.$product_compare_page.'" target="_blank" alt="" title="" style="display:none;">'.$product_view_compare_text.'</a>'; 
  161. $compare_html = '<div class="woo_compare_button_container"><a class="woo_bt_compare_this '.$product_compare_class.' '.$product_compare_custom_class.'" id="woo_bt_compare_this_'.$product_id.'">'.$product_compare_text.'</a>' . $view_compare_html . '<input type="hidden" id="input_woo_bt_compare_this_'.$product_id.'" name="product_compare_'.$product_id.'" value="'.$product_id.'" /></div>'; 
  162. echo $compare_html; 
  163.  
  164. public static function woocp_details_add_compare_button_below_cart($template_name, $template_path, $located) { 
  165. global $post; 
  166. global $product; 
  167. global $woo_compare_product_page_settings; 
  168. global $woo_compare_comparison_page_global_settings; 
  169. global $product_compare_id; 
  170. if (in_array($template_name, array('single-product/add-to-cart/simple.php', 'single-product/add-to-cart/grouped.php', 'single-product/add-to-cart/external.php', 'single-product/add-to-cart/variable.php'))) { 
  171. $product_id = $product->get_id(); 
  172. if (($post->post_type == 'product' || $post->post_type == 'product_variation') && WC_Compare_Functions::check_product_activate_compare($product_id) && $woo_compare_product_page_settings['auto_add'] == 'yes' && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  173.  
  174. $widget_compare_popup_view_button = ''; 
  175. if ( $woo_compare_comparison_page_global_settings['open_compare_type'] != 'new_page' ) $widget_compare_popup_view_button = 'woo_bt_view_compare_popup'; 
  176.  
  177. $product_compare_custom_class = ''; 
  178. $product_compare_text = $woo_compare_product_page_settings['product_compare_button_text']; 
  179. $product_compare_class = 'woo_bt_compare_this_button'; 
  180. if ($woo_compare_product_page_settings['product_compare_button_type'] == 'link') { 
  181. $product_compare_custom_class = ''; 
  182. $product_compare_text = $woo_compare_product_page_settings['product_compare_link_text']; 
  183. $product_compare_class = 'woo_bt_compare_this_link'; 
  184.  
  185. $view_compare_html = ''; 
  186. if ($woo_compare_product_page_settings['disable_product_view_compare'] == 0) { 
  187. $product_view_compare_custom_class = ''; 
  188. $product_view_compare_text = $woo_compare_product_page_settings['product_view_compare_link_text']; 
  189. $product_view_compare_class = 'woo_bt_view_compare_link'; 
  190. if ($woo_compare_product_page_settings['product_view_compare_button_type'] == 'button') { 
  191. $product_view_compare_custom_class = ''; 
  192. $product_view_compare_text = $woo_compare_product_page_settings['product_view_compare_button_text']; 
  193. $product_view_compare_class = 'woo_bt_view_compare_button'; 
  194. $product_compare_page = get_permalink($product_compare_id); 
  195. if ($woo_compare_comparison_page_global_settings['open_compare_type'] != 'new_page') { 
  196. $product_compare_page = '#'; 
  197. $view_compare_html = '<div style="clear:both;"></div><a class="woo_bt_view_compare '.$widget_compare_popup_view_button.' '.$product_view_compare_class.' '.$product_view_compare_custom_class.'" href="'.$product_compare_page.'" target="_blank" alt="" title="" style="display:none;">'.$product_view_compare_text.'</a>'; 
  198.  
  199. $compare_html = '<div class="woo_compare_button_container"><a class="woo_bt_compare_this '.$product_compare_class.' '.$product_compare_custom_class.'" id="woo_bt_compare_this_'.$product_id.'">'.$product_compare_text.'</a>' . $view_compare_html . '<input type="hidden" id="input_woo_bt_compare_this_'.$product_id.'" name="product_compare_'.$product_id.'" value="'.$product_id.'" /></div>'; 
  200. echo $compare_html; 
  201.  
  202. public static function add_compare_button($product_id='') { 
  203. global $post; 
  204. global $woo_compare_product_page_settings; 
  205. global $woo_compare_comparison_page_global_settings; 
  206. global $product_compare_id; 
  207. if (trim($product_id) == '') $product_id = $post->ID; 
  208. $post_type = get_post_type($product_id); 
  209. $html = ''; 
  210. if (($post_type == 'product' || $post_type == 'product_variation') && WC_Compare_Functions::check_product_activate_compare($product_id) && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  211.  
  212. $widget_compare_popup_view_button = ''; 
  213. if ( $woo_compare_comparison_page_global_settings['open_compare_type'] != 'new_page' ) $widget_compare_popup_view_button = 'woo_bt_view_compare_popup'; 
  214.  
  215. $product_compare_custom_class = ''; 
  216. $product_compare_text = $woo_compare_product_page_settings['product_compare_button_text']; 
  217. $product_compare_class = 'woo_bt_compare_this_button'; 
  218. if ($woo_compare_product_page_settings['product_compare_button_type'] == 'link') { 
  219. $product_compare_custom_class = ''; 
  220. $product_compare_text = $woo_compare_product_page_settings['product_compare_link_text']; 
  221. $product_compare_class = 'woo_bt_compare_this_link'; 
  222.  
  223. $view_compare_html = ''; 
  224. if ($woo_compare_product_page_settings['disable_product_view_compare'] == 0) { 
  225. $product_view_compare_custom_class = ''; 
  226. $product_view_compare_text = $woo_compare_product_page_settings['product_view_compare_link_text']; 
  227. $product_view_compare_class = 'woo_bt_view_compare_link'; 
  228. if ($woo_compare_product_page_settings['product_view_compare_button_type'] == 'button') { 
  229. $product_view_compare_custom_class = ''; 
  230. $product_view_compare_text = $woo_compare_product_page_settings['product_view_compare_button_text']; 
  231. $product_view_compare_class = 'woo_bt_view_compare_button'; 
  232. $product_compare_page = get_permalink($product_compare_id); 
  233. if ($woo_compare_comparison_page_global_settings['open_compare_type'] != 'new_page') { 
  234. $product_compare_page = '#'; 
  235. $view_compare_html = '<div style="clear:both;"></div><a class="woo_bt_view_compare '.$widget_compare_popup_view_button.' '.$product_view_compare_class.' '.$product_view_compare_custom_class.'" href="'.$product_compare_page.'" target="_blank" alt="" title="" style="display:none;">'.$product_view_compare_text.'</a>'; 
  236.  
  237. $html .= '<div class="woo_compare_button_container"><a class="woo_bt_compare_this '.$product_compare_class.' '.$product_compare_custom_class.'" id="woo_bt_compare_this_'.$product_id.'">'.$product_compare_text.'</a>' . $view_compare_html . '<input type="hidden" id="input_woo_bt_compare_this_'.$product_id.'" name="product_compare_'.$product_id.'" value="'.$product_id.'" /></div>'; 
  238.  
  239. return $html; 
  240.  
  241. public static function show_compare_fields($product_id='', $use_wootheme_style=true) { 
  242. global $post, $woo_compare_comparison_page_global_settings; 
  243. if (trim($product_id) == '') $product_id = $post->ID; 
  244. $html = ''; 
  245. $variations_list = WC_Compare_Functions::get_variations($product_id); 
  246. if (is_array($variations_list) && count($variations_list) > 0) { 
  247. foreach ($variations_list as $variation_id) { 
  248. if (WC_Compare_Functions::check_product_activate_compare($variation_id) && WC_Compare_Functions::check_product_have_cat($variation_id)) { 
  249. $compare_category = get_post_meta( $variation_id, '_woo_compare_category', true ); 
  250. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$compare_category."'", 'cf.field_order ASC'); 
  251. if (is_array($compare_fields) && count($compare_fields)>0) { 
  252. $html .= '<div class="compare_product_variation"><h2>'.WC_Compare_Functions::get_variation_name($variation_id).'</h2></div>'; 
  253. if ($use_wootheme_style)  
  254. $html .= '<table class="compare_featured_fields shop_attributes">';  
  255. else  
  256. $html .= '<ul class="compare_featured_fields">'; 
  257. $fixed_width = ' width="60%"'; 
  258. foreach ($compare_fields as $field_data) { 
  259. $field_value = get_post_meta( $variation_id, '_woo_compare_'.$field_data->field_key, true ); 
  260. if (is_serialized($field_value)) $field_value = maybe_unserialize($field_value); 
  261. if (is_array($field_value) && count($field_value) > 0) $field_value = implode(', ', $field_value); 
  262. elseif (is_array($field_value) && count($field_value) < 0) $field_value = $woo_compare_comparison_page_global_settings['empty_text']; 
  263. if (trim($field_value) == '') $field_value = $woo_compare_comparison_page_global_settings['empty_text']; 
  264. $field_unit = ''; 
  265. if (trim($field_data->field_unit) != '') $field_unit = ' <span class="compare_featured_unit">('.trim(stripslashes($field_data->field_unit)).')</span>'; 
  266. if ($use_wootheme_style)  
  267. $html .= '<tr><th><span class="compare_featured_name">'.stripslashes($field_data->field_name).'</span>'.$field_unit.'</th><td '.$fixed_width.'><span class="compare_featured_value">'.$field_value.'</span></td></tr>'; 
  268. else 
  269. $html .= '<li class="compare_featured_item"><span class="compare_featured_name"><strong>'.stripslashes($field_data->field_name).'</strong>'.$field_unit.'</span> : <span class="compare_featured_value">'.$field_value.'</span></li>'; 
  270. $fixed_width = ''; 
  271. if ($use_wootheme_style)  
  272. $html .= '</table>'; 
  273. else  
  274. $html .= '</ul>'; 
  275. }elseif (WC_Compare_Functions::check_product_activate_compare($product_id) && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  276. $compare_category = get_post_meta( $product_id, '_woo_compare_category', true ); 
  277. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$compare_category."'", 'cf.field_order ASC'); 
  278. if (is_array($compare_fields) && count($compare_fields)>0) { 
  279. if ($use_wootheme_style)  
  280. $html .= '<table class="compare_featured_fields shop_attributes">';  
  281. else  
  282. $html .= '<ul class="compare_featured_fields">'; 
  283. $fixed_width = ' width="60%"'; 
  284. foreach ($compare_fields as $field_data) { 
  285. $field_value = get_post_meta( $product_id, '_woo_compare_'.$field_data->field_key, true ); 
  286. if (is_serialized($field_value)) $field_value = maybe_unserialize($field_value); 
  287. if (is_array($field_value) && count($field_value) > 0) $field_value = implode(', ', $field_value); 
  288. elseif (is_array($field_value) && count($field_value) < 0) $field_value = $woo_compare_comparison_page_global_settings['empty_text']; 
  289. if (trim($field_value) == '') $field_value = $woo_compare_comparison_page_global_settings['empty_text']; 
  290. $field_unit = ''; 
  291. if (trim($field_data->field_unit) != '') $field_unit = ' <span class="compare_featured_unit">('.trim(stripslashes($field_data->field_unit)).')</span>'; 
  292. if ($use_wootheme_style)  
  293. $html .= '<tr><th><span class="compare_featured_name">'.stripslashes($field_data->field_name).'</span>'.$field_unit.'</th><td '.$fixed_width.'><span class="compare_featured_value">'.$field_value.'</span></td></tr>'; 
  294. else 
  295. $html .= '<li class="compare_featured_item"><span class="compare_featured_name"><strong>'.stripslashes($field_data->field_name).'</strong>'.$field_unit.'</span> : <span class="compare_featured_value">'.$field_value.'</span></li>'; 
  296. $fixed_width = ''; 
  297. if ($use_wootheme_style)  
  298. $html .= '</table>'; 
  299. else  
  300. $html .= '</ul>'; 
  301. return $html; 
  302.  
  303. public static function woocp_variable_ajax_add_to_cart() { 
  304.  
  305. // Get product ID to add and quantity 
  306. $variation_id = (int) $_REQUEST['product_id']; 
  307. $mypost = get_post($variation_id); 
  308. $product_id = (int) apply_filters('woocommerce_add_to_cart_product_id', $mypost->post_parent); 
  309. $quantity = (isset($_REQUEST['quantity'])) ? (int) $_REQUEST['quantity'] : 1; 
  310. $attributes = (array) maybe_unserialize(get_post_meta($product_id, '_product_attributes', true)); 
  311. $variations = array(); 
  312.  
  313. $my_variation = new WC_Product_Variation($variation_id, $product_id); 
  314. $variation_data = $my_variation->get_variation_attributes(); 
  315.  
  316. // Add to cart validation 
  317. $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity); 
  318.  
  319. if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variation_data)) { 
  320. // Return html fragments 
  321. $data = apply_filters('add_to_cart_fragments', array()); 
  322.  
  323. // For WC 2.3 
  324. $data = apply_filters('woocommerce_add_to_cart_fragments', $data); 
  325. } else { 
  326. $data = array( 
  327. 'error' => true,  
  328. 'product_url' => get_permalink( $product_id ) 
  329. ); 
  330.  
  331. echo json_encode( $data ); 
  332. die(); 
  333.  
  334. public static function woocp_add_to_compare() { 
  335.  
  336. $product_id = $_REQUEST['product_id']; 
  337. WC_Compare_Functions::add_product_to_compare_list($product_id); 
  338.  
  339. die(); 
  340.  
  341. public static function woocp_remove_from_popup_compare() { 
  342.  
  343. $product_id = $_REQUEST['product_id']; 
  344. WC_Compare_Functions::delete_product_on_compare_list($product_id); 
  345.  
  346. die(); 
  347.  
  348. public static function woocp_update_compare_popup() { 
  349. $result = WC_Compare_Functions::get_compare_list_html_popup(); 
  350. $result .= '<script src="'. WOOCP_JS_URL.'/fixedcolumntable/fixedcolumntable.js"></script>'; 
  351. echo json_encode( $result ); 
  352. die(); 
  353.  
  354. public static function woocp_update_compare_widget() { 
  355. $result = WC_Compare_Functions::get_compare_list_html_widget(); 
  356. echo json_encode( $result ); 
  357. die(); 
  358.  
  359. public static function woocp_update_total_compare() { 
  360. $result = WC_Compare_Functions::get_total_compare_list(); 
  361. echo json_encode( $result ); 
  362. die(); 
  363.  
  364. public static function woocp_remove_from_compare() { 
  365. $product_id = $_REQUEST['product_id']; 
  366. WC_Compare_Functions::delete_product_on_compare_list($product_id); 
  367. die(); 
  368.  
  369. public static function woocp_clear_compare() { 
  370. WC_Compare_Functions::clear_compare_list(); 
  371. die(); 
  372.  
  373. public static function woocp_footer_script() { 
  374. global $product_compare_id; 
  375. global $woo_compare_comparison_page_global_settings; 
  376. $woocp_compare_events = wp_create_nonce("woocp-compare-events"); 
  377. $woocp_compare_popup = wp_create_nonce("woocp-compare-popup"); 
  378.  
  379. $script_add_on = ''; 
  380. $script_add_on .= '<script type="text/javascript"> 
  381. jQuery(document).ready(function($) { 
  382. var ajax_url = "'.admin_url( 'admin-ajax.php', 'relative' ).'"; 
  383. woo_compare_widget_load();'; 
  384.  
  385. $script_add_on .= ' 
  386. $(document).on("click", ".woo_compare_popup_button_go, .woo_bt_view_compare_popup", function (event) { 
  387. var compare_url = "'.get_permalink($product_compare_id).'"; 
  388. window.open(compare_url, "'.__('Product_Comparison', 'woocommerce-compare-products' ).'", "scrollbars=1, width=980, height=650"); 
  389. event.preventDefault(); 
  390. return false; 
  391.  
  392. });'; 
  393.  
  394. $script_add_on .= ' 
  395. $(document).on("click", ".woo_bt_compare_this", function() { 
  396. var woo_bt_compare_current = $(this); 
  397. var product_id = $("#input_"+$(this).attr("id")).val(); 
  398. $(".woo_compare_widget_loader").show(); 
  399. $(".woo_compare_widget_container").html(""); 
  400. var data = { 
  401. action: "woocp_add_to_compare",  
  402. product_id: product_id,  
  403. security: "'.$woocp_compare_events.'" 
  404. }; 
  405. $.post( ajax_url, data, function(response) { 
  406. //woo_bt_compare_current.siblings(".woo_add_compare_success").show(); 
  407. woo_bt_compare_current.addClass("compared"); 
  408. woo_bt_compare_current.siblings(".woo_bt_view_compare").show(); 
  409. //setTimeout(function() { 
  410. // woo_bt_compare_current.siblings(".woo_add_compare_success").hide(); 
  411. //}, 3000); 
  412. data = { 
  413. action: "woocp_update_compare_widget",  
  414. security: "'.$woocp_compare_events.'" 
  415. }; 
  416. $.post( ajax_url, data, function(response) { 
  417. result = $.parseJSON( response ); 
  418. $(".woo_compare_widget_loader").hide(); 
  419. $(".woo_compare_widget_container").html(result); 
  420. }); 
  421. woo_update_total_compare_list(); 
  422. }); 
  423. }); 
  424.  
  425. $(document).on("click", ".woo_compare_remove_product", function() { 
  426. var remove_product_id = $(this).attr("rel"); 
  427. $(".woo_compare_widget_loader").show(); 
  428. $(".woo_compare_widget_container").html(""); 
  429. var data = { 
  430. action: "woocp_remove_from_compare",  
  431. product_id: remove_product_id,  
  432. security: "'.$woocp_compare_events.'" 
  433. }; 
  434. $.post( ajax_url, data, function(response) { 
  435. data = { 
  436. action: "woocp_update_compare_widget",  
  437. security: "'.$woocp_compare_events.'" 
  438. }; 
  439. $.post( ajax_url, data, function(response) { 
  440. result = $.parseJSON( response ); 
  441. $(".woo_compare_widget_loader").hide(); 
  442. $(".woo_compare_widget_container").html(result); 
  443. }); 
  444. woo_update_total_compare_list(); 
  445. }); 
  446. }); 
  447. $(document).on("click", ".woo_compare_clear_all", function() { 
  448. $(".woo_compare_widget_loader").show(); 
  449. $(".woo_compare_widget_container").html(""); 
  450. var data = { 
  451. action: "woocp_clear_compare",  
  452. security: "'.$woocp_compare_events.'" 
  453. }; 
  454. $.post( ajax_url, data, function(response) { 
  455. data = { 
  456. action: "woocp_update_compare_widget",  
  457. security: "'.$woocp_compare_events.'" 
  458. }; 
  459. $.post( ajax_url, data, function(response) { 
  460. result = $.parseJSON( response ); 
  461. $(".woo_compare_widget_loader").hide(); 
  462. $(".woo_compare_widget_container").html(result); 
  463. }); 
  464. woo_update_total_compare_list(); 
  465. }); 
  466. }); 
  467.  
  468. function woo_update_total_compare_list() { 
  469. var data = { 
  470. action: "woocp_update_total_compare",  
  471. security: "'.$woocp_compare_events.'" 
  472. }; 
  473. $.post( ajax_url, data, function(response) { 
  474. total_compare = $.parseJSON( response ); 
  475. $("#total_compare_product").html(total_compare); 
  476. }); 
  477.  
  478. function woo_compare_widget_load() { 
  479. $(".woo_compare_widget_loader").show(); 
  480. $(".woo_compare_widget_container").html(""); 
  481. var data = { 
  482. action: "woocp_update_compare_widget",  
  483. security: "'.$woocp_compare_events.'" 
  484. }; 
  485. $.post( ajax_url, data, function(response) { 
  486. result = $.parseJSON( response ); 
  487. $(".woo_compare_widget_loader").hide(); 
  488. $(".woo_compare_widget_container").html(result); 
  489. }); 
  490. woo_update_total_compare_list(); 
  491.  
  492. }); 
  493. </script>'; 
  494. echo $script_add_on; 
  495.  
  496. public static function woocp_variable_add_to_cart_script() { 
  497. $woocp_add_to_cart_nonce = wp_create_nonce("woocp-add-to-cart"); 
  498. $script_add_on = ''; 
  499. $script_add_on .= '<script type="text/javascript"> 
  500. (function($) { 
  501. $(function() { 
  502. if ( typeof wc_add_to_cart_params !== "undefined" ) { 
  503.  
  504. // Ajax add to cart 
  505. $(document).on("click", ".add_to_cart_button", function() { 
  506.  
  507. // AJAX add to cart request 
  508. var $thisbutton = $(this); 
  509.  
  510. if ($thisbutton.is(".product_type_variation")) { 
  511. if (!$thisbutton.attr("data-product_id")) return true; 
  512.  
  513. $thisbutton.removeClass("added"); 
  514. $thisbutton.addClass("loading"); 
  515.  
  516. var data = { 
  517. action: "woocp_variable_add_to_cart",  
  518. product_id: $thisbutton.attr("data-product_id"),  
  519. security: "'.$woocp_add_to_cart_nonce.'" 
  520. }; 
  521.  
  522. // Trigger event 
  523. $("body").trigger("adding_to_cart"); 
  524.  
  525. // Ajax action 
  526. $.post( wc_add_to_cart_params.ajax_url, data, function(response) { 
  527.  
  528. $thisbutton.removeClass("loading"); 
  529.  
  530. // Get response 
  531. data = $.parseJSON( response ); 
  532.  
  533. if (data.error && data.product_url) { 
  534. window.location = data.product_url; 
  535. return; 
  536.  
  537. fragments = data; 
  538.  
  539. // Block fragments class 
  540. if (fragments) { 
  541. $.each(fragments, function(key, value) { 
  542. $(key).addClass("updating"); 
  543. }); 
  544.  
  545. // Block widgets and fragments 
  546. $(".widget_shopping_cart, .shop_table.cart, .updating, .cart_totals").fadeTo("400", "0.6").block({message: null, overlayCSS: {background: "transparent url('.str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ).'/assets/images/ajax-loader.gif) no-repeat center", opacity: 0.6}}); 
  547.  
  548. // Changes button classes 
  549. $thisbutton.addClass("added"); 
  550.  
  551. // Cart widget load 
  552. if ($(".widget_shopping_cart").size()>0) { 
  553. $(".widget_shopping_cart:eq(0)").load( window.location + " .widget_shopping_cart:eq(0) > *", function() { 
  554.  
  555. // Replace fragments 
  556. if (fragments) { 
  557. $.each(fragments, function(key, value) { 
  558. $(key).replaceWith(value); 
  559. }); 
  560.  
  561. // Unblock 
  562. $(".widget_shopping_cart, .updating").css("opacity", "1").unblock(); 
  563.  
  564. $("body").trigger("cart_widget_refreshed"); 
  565. } ); 
  566. } else { 
  567. // Replace fragments 
  568. if (fragments) { 
  569. $.each(fragments, function(key, value) { 
  570. $(key).replaceWith(value); 
  571. }); 
  572.  
  573. // Unblock 
  574. $(".widget_shopping_cart, .updating").css("opacity", "1").unblock(); 
  575.  
  576. // Cart page elements 
  577. $(".shop_table.cart").load( window.location + " .shop_table.cart:eq(0) > *", function() { 
  578.  
  579. $("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append("<input type=\"button\" value=\"+\" id=\"add1\" class=\"plus\" />").prepend("<input type=\"button\" value=\"-\" id=\"minus1\" class=\"minus\" />"); 
  580.  
  581. $(".shop_table.cart").css("opacity", "1").unblock(); 
  582.  
  583. $("body").trigger("cart_page_refreshed"); 
  584. }); 
  585.  
  586. $(".cart_totals").load( window.location + " .cart_totals:eq(0) > *", function() { 
  587. $(".cart_totals").css("opacity", "1").unblock(); 
  588. }); 
  589.  
  590. // Trigger event so themes can refresh other areas 
  591. $("body").trigger("added_to_cart"); 
  592.  
  593. }); 
  594.  
  595. return false; 
  596.  
  597. } else { 
  598. return true; 
  599.  
  600. }); 
  601. }); 
  602. })(jQuery); 
  603. </script>'; 
  604. echo $script_add_on; 
  605.  
  606. public static function woocp_product_featured_tab() { 
  607. global $post; 
  608. global $woo_compare_product_page_settings; 
  609. $compare_featured_tab = trim($woo_compare_product_page_settings['compare_featured_tab']); 
  610. if ($compare_featured_tab == '') $compare_featured_tab = __('Technical Details', 'woocommerce-compare-products' ); 
  611.  
  612. $show_compare_featured_tab = false; 
  613. $product_id = $post->ID; 
  614. $variations_list = WC_Compare_Functions::get_variations($product_id); 
  615. if (is_array($variations_list) && count($variations_list) > 0) { 
  616. foreach ($variations_list as $variation_id) { 
  617. if (WC_Compare_Functions::check_product_activate_compare($variation_id) && WC_Compare_Functions::check_product_have_cat($variation_id)) { 
  618. $compare_category = get_post_meta( $variation_id, '_woo_compare_category', true ); 
  619. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$compare_category."'", 'cf.field_order ASC'); 
  620. if (is_array($compare_fields) && count($compare_fields)>0) { 
  621. $show_compare_featured_tab = true; 
  622. break; 
  623. }elseif (WC_Compare_Functions::check_product_activate_compare($product_id) && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  624. $compare_category = get_post_meta( $product_id, '_woo_compare_category', true ); 
  625. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$compare_category."'", 'cf.field_order ASC'); 
  626. if (is_array($compare_fields) && count($compare_fields)>0) { 
  627. $show_compare_featured_tab = true; 
  628.  
  629. if ($show_compare_featured_tab) echo '<li><a href="#tab-compare-featured">'.esc_attr( stripslashes( $compare_featured_tab ) ).'</a></li>'; 
  630.  
  631. public static function woocp_product_featured_tab_woo_2_0( $tabs = array() ) { 
  632. global $product, $post; 
  633. global $woo_compare_product_page_settings; 
  634.  
  635. $compare_featured_tab = trim($woo_compare_product_page_settings['compare_featured_tab']); 
  636. if ($compare_featured_tab == '') $compare_featured_tab = __('Technical Details', 'woocommerce-compare-products' ); 
  637.  
  638. $show_compare_featured_tab = false; 
  639. $product_id = $post->ID; 
  640. $variations_list = WC_Compare_Functions::get_variations($product_id); 
  641. if (is_array($variations_list) && count($variations_list) > 0) { 
  642. foreach ($variations_list as $variation_id) { 
  643. if (WC_Compare_Functions::check_product_activate_compare($variation_id) && WC_Compare_Functions::check_product_have_cat($variation_id)) { 
  644. $compare_category = get_post_meta( $variation_id, '_woo_compare_category', true ); 
  645. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$compare_category."'", 'cf.field_order ASC'); 
  646. if (is_array($compare_fields) && count($compare_fields)>0) { 
  647. $show_compare_featured_tab = true; 
  648. break; 
  649. }elseif (WC_Compare_Functions::check_product_activate_compare($product_id) && WC_Compare_Functions::check_product_have_cat($product_id)) { 
  650. $compare_category = get_post_meta( $product_id, '_woo_compare_category', true ); 
  651. $compare_fields = WC_Compare_Categories_Fields_Data::get_results("cat_id='".$compare_category."'", 'cf.field_order ASC'); 
  652. if (is_array($compare_fields) && count($compare_fields)>0) { 
  653. $show_compare_featured_tab = true; 
  654.  
  655. if ($show_compare_featured_tab) { 
  656.  
  657. $tabs['compare-featured'] = array( 
  658. 'title' => esc_attr( stripslashes( $compare_featured_tab ) ),  
  659. 'priority' => $woo_compare_product_page_settings['auto_compare_featured_tab'],  
  660. 'callback' => array('WC_Compare_Hook_Filter', 'woocp_product_featured_panel_woo_2_0') 
  661. ); 
  662.  
  663. return $tabs; 
  664.  
  665. public static function woocp_product_featured_panel() { 
  666. global $post; 
  667. ?> 
  668. <div class="panel entry-content" id="tab-compare-featured"> 
  669. <?php echo WC_Compare_Hook_Filter::show_compare_fields($post->ID); ?> 
  670. </div> 
  671. <?php 
  672.  
  673. public static function woocp_product_featured_panel_woo_2_0() { 
  674. global $post; 
  675. echo WC_Compare_Hook_Filter::show_compare_fields($post->ID); 
  676.  
  677. public static function woocp_set_selected_attributes($default_attributes) { 
  678. if (isset($_REQUEST['variation_selected']) && $_REQUEST['variation_selected'] > 0) { 
  679. $variation_id = $_REQUEST['variation_selected']; 
  680. $mypost = get_post($variation_id); 
  681. if ($mypost != NULL && $mypost->post_type == 'product_variation') { 
  682. $attributes = (array) maybe_unserialize(get_post_meta($mypost->post_parent, '_product_attributes', true)); 
  683. $my_variation = new WC_Product_Variation($variation_id, $mypost->post_parent); 
  684. $variation_data = $my_variation->get_variation_attributes(); 
  685. if (is_array($attributes) && count($attributes) > 0) { 
  686. foreach ($attributes as $attribute) { 
  687. if ( !$attribute['is_variation'] ) continue; 
  688. $taxonomy = 'attribute_' . sanitize_title($attribute['name']); 
  689. if (isset($variation_data[$taxonomy])) { 
  690. $default_attributes[sanitize_title($attribute['name'])] = $variation_data[$taxonomy];  
  691. return $default_attributes; 
  692.  
  693. public static function auto_create_compare_category($term_id) { 
  694. $term = get_term( $term_id, 'product_cat' ); 
  695. $check_existed = WC_Compare_Categories_Data::get_count("category_name='".trim($term->name)."'"); 
  696. if ($check_existed < 1 ) { 
  697. WC_Compare_Categories_Data::insert_row(array('category_name' => trim(addslashes($term->name)))); 
  698.  
  699. public static function auto_create_compare_feature() { 
  700. if (isset($_POST['add_new_attribute']) && $_POST['add_new_attribute']) { 
  701. //check_admin_referer( 'woocommerce-add-new_attribute' ); 
  702. $attribute_name = (string) sanitize_title($_POST['attribute_name']); 
  703. $attribute_type = (string) $_POST['attribute_type']; 
  704. $attribute_label = (string) $_POST['attribute_label']; 
  705.  
  706. if (!$attribute_label) $attribute_label = ucwords($attribute_name); 
  707.  
  708. if (!$attribute_name) $attribute_name = sanitize_title($attribute_label); 
  709.  
  710. if ($attribute_name && strlen($attribute_name)<30 && $attribute_type && !taxonomy_exists( 'pa_'.$attribute_name )) { 
  711.  
  712. $check_existed = WC_Compare_Data::get_count("field_name='".$attribute_label."'"); 
  713. if ($check_existed < 1 ) { 
  714. $feature_id = WC_Compare_Data::insert_row(array('field_name' => $attribute_label, 'field_type' => 'input-text', 'field_unit' => '', 'default_value' => '' ) ); 
  715.  
  716. public static function a3_wp_admin() { 
  717. wp_enqueue_style( 'a3rev-wp-admin-style', WOOCP_CSS_URL . '/a3_wp_admin.css' ); 
  718.  
  719. public static function admin_sidebar_menu_css() { 
  720. wp_enqueue_style( 'a3rev-wc-cp-admin-sidebar-menu-style', WOOCP_CSS_URL . '/admin_sidebar_menu.css' ); 
  721.  
  722. public static function plugin_extension_box( $boxes = array() ) { 
  723. global $wc_compare_admin_init; 
  724.  
  725. $support_box = '<a href="'.$wc_compare_admin_init->support_url.'" target="_blank" alt="'.__('Go to Support Forum', 'woocommerce-compare-products' ).'"><img src="'.WOOCP_IMAGES_URL.'/go-to-support-forum.png" /></a>'; 
  726.  
  727. $boxes[] = array( 
  728. 'content' => $support_box,  
  729. 'css' => 'border: none; padding: 0; background: none;' 
  730. ); 
  731.  
  732. $review_box = '<div style="margin-bottom: 5px; font-size: 12px;"><strong>' . __('Is this plugin is just what you needed? If so', 'woocommerce-compare-products' ) . '</strong></div>'; 
  733. $review_box .= '<a href="https://wordpress.org/support/view/plugin-reviews/woocommerce-compare-products#postform" target="_blank" alt="'.__('Submit Review for Plugin on WordPress', 'woocommerce-compare-products' ).'"><img src="'.WOOCP_IMAGES_URL.'/a-5-star-rating-would-be-appreciated.png" /></a>'; 
  734.  
  735. $boxes[] = array( 
  736. 'content' => $review_box,  
  737. 'css' => 'border: none; padding: 0; background: none;' 
  738. ); 
  739.  
  740. $pro_box = '<a href="'.$wc_compare_admin_init->pro_plugin_page_url.'" target="_blank" alt="'.__('WooCommerce Compare Product', 'woocommerce-compare-products' ).'"><img src="'.WOOCP_IMAGES_URL.'/pro-version.jpg" /></a>'; 
  741.  
  742. $boxes[] = array( 
  743. 'content' => $pro_box,  
  744. 'css' => 'border: none; padding: 0; background: none;' 
  745. ); 
  746.  
  747. $free_woocommerce_box = '<a href="https://profiles.wordpress.org/a3rev/#content-plugins" target="_blank" alt="'.__('Free WooCommerce Plugins', 'woocommerce-compare-products' ).'"><img src="'.WOOCP_IMAGES_URL.'/free-woocommerce-plugins.png" /></a>'; 
  748.  
  749. $boxes[] = array( 
  750. 'content' => $free_woocommerce_box,  
  751. 'css' => 'border: none; padding: 0; background: none;' 
  752. ); 
  753.  
  754. $free_wordpress_box = '<a href="https://profiles.wordpress.org/a3rev/#content-plugins" target="_blank" alt="'.__('Free WordPress Plugins', 'woocommerce-compare-products' ).'"><img src="'.WOOCP_IMAGES_URL.'/free-wordpress-plugins.png" /></a>'; 
  755.  
  756. $boxes[] = array( 
  757. 'content' => $free_wordpress_box,  
  758. 'css' => 'border: none; padding: 0; background: none;' 
  759. ); 
  760.  
  761. $connect_box = '<div style="margin-bottom: 5px;">' . __('Connect with us via', 'woocommerce-compare-products' ) . '</div>'; 
  762. $connect_box .= '<a href="https://www.facebook.com/a3rev" target="_blank" alt="'.__('a3rev Facebook', 'woocommerce-compare-products' ).'" style="margin-right: 5px;"><img src="'.WOOCP_IMAGES_URL.'/follow-facebook.png" /></a> '; 
  763. $connect_box .= '<a href="https://twitter.com/a3rev" target="_blank" alt="'.__('a3rev Twitter', 'woocommerce-compare-products' ).'"><img src="'.WOOCP_IMAGES_URL.'/follow-twitter.png" /></a>'; 
  764.  
  765. $boxes[] = array( 
  766. 'content' => $connect_box,  
  767. 'css' => 'border-color: #3a5795;' 
  768. ); 
  769.  
  770. return $boxes; 
  771.  
  772. public static function plugin_extra_links($links, $plugin_name) { 
  773. if ( $plugin_name != WOOCP_NAME) { 
  774. return $links; 
  775.  
  776. global $wc_compare_admin_init; 
  777. $links[] = '<a href="http://docs.a3rev.com/user-guides/woocommerce/compare-products/" target="_blank">'.__('Documentation', 'woocommerce-compare-products' ).'</a>'; 
  778. $links[] = '<a href="'.$wc_compare_admin_init->support_url.'" target="_blank">'.__('Support', 'woocommerce-compare-products' ).'</a>'; 
  779. return $links; 
  780.  
  781. public static function settings_plugin_links($actions) { 
  782. $actions = array_merge( array( 'settings' => '<a href="admin.php?page=woo-compare-settings">' . __( 'Settings', 'woocommerce-compare-products' ) . '</a>' ), $actions ); 
  783.  
  784. return $actions;