WC_Compare_Product_Page_Global_Settings

The WooCommerce Compare Products LITE WC Compare Product Page Global Settings class.

Defined (1)

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

/admin/settings/product-page/global-settings.php  
  1. class WC_Compare_Product_Page_Global_Settings extends WC_Compare_Admin_UI 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. private $parent_tab = 'product-page'; 
  7.  
  8. /** 
  9. * @var array 
  10. */ 
  11. private $subtab_data; 
  12.  
  13. /** 
  14. * @var string 
  15. * You must change to correct option name that you are working 
  16. */ 
  17. public $option_name = 'woo_compare_product_page_settings'; 
  18.  
  19. /** 
  20. * @var string 
  21. * You must change to correct form key that you are working 
  22. */ 
  23. public $form_key = 'woo_compare_product_page_settings'; 
  24.  
  25. /** 
  26. * @var string 
  27. * You can change the order show of this sub tab in list sub tabs 
  28. */ 
  29. private $position = 1; 
  30.  
  31. /** 
  32. * @var array 
  33. */ 
  34. public $form_fields = array(); 
  35.  
  36. /** 
  37. * @var array 
  38. */ 
  39. public $form_messages = array(); 
  40.  
  41. /**-----------------------------------------------------------------------------------*/ 
  42. /** __construct() */ 
  43. /** Settings Constructor */ 
  44. /**-----------------------------------------------------------------------------------*/ 
  45. public function __construct() { 
  46.  
  47. add_action( 'plugins_loaded', array( $this, 'init_form_fields' ), 1 ); 
  48. $this->subtab_init(); 
  49.  
  50. $this->form_messages = array( 
  51. 'success_message' => __( 'Product Page Settings successfully saved.', 'woocommerce-compare-products' ),  
  52. 'error_message' => __( 'Error: Product Page Settings can not save.', 'woocommerce-compare-products' ),  
  53. 'reset_message' => __( 'Product Page Settings successfully reseted.', 'woocommerce-compare-products' ),  
  54. ); 
  55.  
  56. add_action( $this->plugin_name . '-' . $this->form_key . '_settings_end', array( $this, 'include_script' ) ); 
  57.  
  58. add_action( $this->plugin_name . '_set_default_settings' , array( $this, 'set_default_settings' ) ); 
  59.  
  60. add_action( $this->plugin_name . '_get_all_settings' , array( $this, 'get_settings' ) ); 
  61.  
  62. /**-----------------------------------------------------------------------------------*/ 
  63. /** subtab_init() */ 
  64. /** Sub Tab Init */ 
  65. /**-----------------------------------------------------------------------------------*/ 
  66. public function subtab_init() { 
  67.  
  68. add_filter( $this->plugin_name . '-' . $this->parent_tab . '_settings_subtabs_array', array( $this, 'add_subtab' ), $this->position ); 
  69.  
  70.  
  71. /**-----------------------------------------------------------------------------------*/ 
  72. /** set_default_settings() 
  73. /** Set default settings with function called from Admin Interface */ 
  74. /**-----------------------------------------------------------------------------------*/ 
  75. public function set_default_settings() { 
  76. global $wc_compare_admin_interface; 
  77.  
  78. $wc_compare_admin_interface->reset_settings( $this->form_fields, $this->option_name, false ); 
  79.  
  80. /**-----------------------------------------------------------------------------------*/ 
  81. /** get_settings() 
  82. /** Get settings with function called from Admin Interface */ 
  83. /**-----------------------------------------------------------------------------------*/ 
  84. public function get_settings() { 
  85. global $wc_compare_admin_interface; 
  86.  
  87. $wc_compare_admin_interface->get_settings( $this->form_fields, $this->option_name ); 
  88.  
  89. /** 
  90. * subtab_data() 
  91. * Get SubTab Data 
  92. * ============================================= 
  93. * array (  
  94. * 'name' => 'my_subtab_name' : (required) Enter your subtab name that you want to set for this subtab 
  95. * 'label' => 'My SubTab Name' : (required) Enter the subtab label 
  96. * 'callback_function' => 'my_callback_function' : (required) The callback function is called to show content of this subtab 
  97. * ) 
  98. */ 
  99. public function subtab_data() { 
  100.  
  101. $subtab_data = array(  
  102. 'name' => 'product-page-settings',  
  103. 'label' => __( 'Product Page Settings', 'woocommerce-compare-products' ),  
  104. 'callback_function' => 'wc_compare_product_page_global_settings_form',  
  105. ); 
  106.  
  107. if ( $this->subtab_data ) return $this->subtab_data; 
  108. return $this->subtab_data = $subtab_data; 
  109.  
  110.  
  111. /**-----------------------------------------------------------------------------------*/ 
  112. /** add_subtab() */ 
  113. /** Add Subtab to Admin Init 
  114. /**-----------------------------------------------------------------------------------*/ 
  115. public function add_subtab( $subtabs_array ) { 
  116.  
  117. if ( ! is_array( $subtabs_array ) ) $subtabs_array = array(); 
  118. $subtabs_array[] = $this->subtab_data(); 
  119.  
  120. return $subtabs_array; 
  121.  
  122. /**-----------------------------------------------------------------------------------*/ 
  123. /** settings_form() */ 
  124. /** Call the form from Admin Interface 
  125. /**-----------------------------------------------------------------------------------*/ 
  126. public function settings_form() { 
  127. global $wc_compare_admin_interface; 
  128.  
  129. $output = ''; 
  130. $output .= $wc_compare_admin_interface->admin_forms( $this->form_fields, $this->form_key, $this->option_name, $this->form_messages ); 
  131.  
  132. return $output; 
  133.  
  134. /**-----------------------------------------------------------------------------------*/ 
  135. /** init_form_fields() */ 
  136. /** Init all fields of this form */ 
  137. /**-----------------------------------------------------------------------------------*/ 
  138. public function init_form_fields() { 
  139.  
  140. // Define settings 
  141. $this->form_fields = array( 
  142. array( 
  143. 'name' => __( "Add to Compare from Product Page", 'woocommerce-compare-products' ),  
  144. 'type' => 'heading',  
  145. 'id' => 'show_compare_product_pages_box',  
  146. 'is_box' => true,  
  147. ),  
  148. array( 
  149. 'name' => __( "Compare Feature", 'woocommerce-compare-products' ),  
  150. 'class' => 'disable_product_page_compare',  
  151. 'id' => 'disable_product_page_compare',  
  152. 'type' => 'onoff_checkbox',  
  153. 'default' => 0,  
  154. 'checked_value' => 0,  
  155. 'unchecked_value' => 1,  
  156. 'checked_label' => __( 'ON', 'woocommerce-compare-products' ),  
  157. 'unchecked_label' => __( 'OFF', 'woocommerce-compare-products' ),  
  158. ),  
  159.  
  160. ); 
  161.  
  162. include_once( $this->admin_plugin_dir() . '/settings/product-page/compare-button-settings.php' ); 
  163. global $wc_compare_product_page_compare_button_settings; 
  164. $this->form_fields = array_merge( $this->form_fields, $wc_compare_product_page_compare_button_settings->form_fields ); 
  165.  
  166. $this->form_fields = array_merge( $this->form_fields, array( 
  167. array( 
  168. 'name' => __( "Button / Hyperlink Position", 'woocommerce-compare-products' ),  
  169. 'id' => 'produc_page_activate_box',  
  170. 'class' => 'produc_page_compare_button_activate_container',  
  171. 'type' => 'heading',  
  172. 'is_box' => true,  
  173. ),  
  174. array( 
  175. 'name' => __( 'Button/ Hyperlink Position', 'woocommerce-compare-products' ),  
  176. 'desc' => __( 'Position relative to Add to Cart button location', 'woocommerce-compare-products' ),  
  177. 'id' => 'product_page_button_position',  
  178. 'type' => 'switcher_checkbox',  
  179. 'default' => 'above',  
  180. 'checked_value' => 'above',  
  181. 'unchecked_value' => 'below',  
  182. 'checked_label' => __( 'Above', 'woocommerce-compare-products' ),  
  183. 'unchecked_label' => __( 'Below', 'woocommerce-compare-products' ),  
  184. ),  
  185. array(  
  186. 'name' => __( 'Button Margin', 'woocommerce-compare-products' ),  
  187. 'id' => 'product_page_button_margin',  
  188. 'type' => 'array_textfields',  
  189. 'ids' => array(  
  190. array(  
  191. 'id' => 'product_page_button_margin_top',  
  192. 'name' => __( 'Top', 'woocommerce-compare-products' ),  
  193. 'css' => 'width:40px;',  
  194. 'default' => 10 ),  
  195.  
  196. array( 'id' => 'product_page_button_margin_bottom',  
  197. 'name' => __( 'Bottom', 'woocommerce-compare-products' ),  
  198. 'css' => 'width:40px;',  
  199. 'default' => 10 ),  
  200.  
  201. array(  
  202. 'id' => 'product_page_button_margin_left',  
  203. 'name' => __( 'Left', 'woocommerce-compare-products' ),  
  204. 'css' => 'width:40px;',  
  205. 'default' => 0 ),  
  206.  
  207. array(  
  208. 'id' => 'product_page_button_margin_right',  
  209. 'name' => __( 'Right', 'woocommerce-compare-products' ),  
  210. 'css' => 'width:40px;',  
  211. 'default' => 0 ),  
  212. ),  
  213. array(  
  214. 'name' => __( "Custom Position", 'woocommerce-compare-products' ),  
  215. 'desc' => __( "ON to deactivate default button position settings created by the plugin.", 'woocommerce-compare-products' ).'<br />'.__('Then use this function to manually postion the Compare button on product pages', 'woocommerce-compare-products' )."<br /><code><?php if ( function_exists('woo_add_compare_button' ) ) echo woo_add_compare_button(); ?></code>",  
  216. 'id' => 'auto_add',  
  217. 'type' => 'onoff_checkbox',  
  218. 'default' => 'yes',  
  219. 'checked_value' => 'no',  
  220. 'unchecked_value' => 'yes',  
  221. 'checked_label' => __( 'ON', 'woocommerce-compare-products' ),  
  222. 'unchecked_label' => __( 'OFF', 'woocommerce-compare-products' ),  
  223. ),  
  224. )); 
  225.  
  226. include_once( $this->admin_plugin_dir() . '/settings/product-page/view-compare-settings.php' ); 
  227. global $wc_compare_product_page_view_compare_button_settings; 
  228. $this->form_fields = array_merge( $this->form_fields, $wc_compare_product_page_view_compare_button_settings->form_fields ); 
  229.  
  230. include_once( $this->admin_plugin_dir() . '/settings/product-page/compare-tab-settings.php' ); 
  231. global $wc_compare_product_page_compare_tab_settings; 
  232. $this->form_fields = array_merge( $this->form_fields, $wc_compare_product_page_compare_tab_settings->form_fields ); 
  233.  
  234. $this->form_fields = apply_filters( $this->form_key . '_settings_fields', $this->form_fields ); 
  235.  
  236. public function include_script() { 
  237. global $wc_compare_product_page_compare_button_settings; 
  238. global $wc_compare_product_page_view_compare_button_settings; 
  239. global $wc_compare_product_page_compare_tab_settings; 
  240. ?> 
  241. <script> 
  242. (function($) { 
  243.  
  244. $(document).ready(function() { 
  245.  
  246. if ( $("input.disable_product_page_compare:checked").val() != '0') { 
  247. $(".produc_page_compare_button_activate_container").css( {'visibility': 'hidden', 'height' : '0px', 'overflow' : 'hidden', 'margin-bottom' : '0px'} ); 
  248.  
  249. $(document).on( "a3rev-ui-onoff_checkbox-switch", '.disable_product_page_compare', function( event, value, status ) { 
  250. $('.produc_page_compare_button_activate_container').attr('style', 'display:none;'); 
  251. if ( status == 'true' ) { 
  252. $(".produc_page_compare_button_activate_container").slideDown(); 
  253. }); 
  254.  
  255. }); 
  256.  
  257. })(jQuery); 
  258. </script> 
  259. <?php 
  260. $wc_compare_product_page_compare_button_settings->include_script(); 
  261. $wc_compare_product_page_view_compare_button_settings->include_script(); 
  262. $wc_compare_product_page_compare_tab_settings->include_script(); 
  263.