WC_Admin_Compare_Features

Handles compare categories in admin.

Defined (1)

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

/classes/class-wc-compare-features.php  
  1. class WC_Admin_Compare_Features { 
  2.  
  3. public $default_types = array( 
  4. 'input-text' => array('name' => 'Input Text', 'description' => 'Enter Attribute compare data in single line text box'),  
  5. 'text-area' => array('name' => 'Text Area', 'description' => 'Enter Attribute compare data in paragraph text box'),  
  6. 'checkbox' => array('name' => 'Check Box', 'description' => 'Attribute Terms show as multi select check boxes'),  
  7. 'radio' => array('name' => 'Radio button', 'description' => 'Attribute Terms show as single select check boxes'),  
  8. 'drop-down' => array('name' => 'Drop Down', 'description' => 'Attribute Terms show in dropdown, single select'),  
  9. 'multi-select' => array('name' => 'Multi Select', 'description' => 'Attribute Terms show in dropdown, multi select'),  
  10. 'wp-video' => array('name' => 'Video Player', 'description' => 'Attribute with text field to add Video URL'),  
  11. 'wp-audio' => array('name' => 'Audio Player', 'description' => 'Attribute with text field to add Audio URL'),  
  12. ); 
  13.  
  14. /** 
  15. * Constructor 
  16. */ 
  17. public function __construct() { 
  18.  
  19. // Include script 
  20. add_action( 'admin_footer', array( $this, 'include_script' ) ); 
  21.  
  22.  
  23. /** 
  24. * Include script to append the Compare Feature meta fields into Product Attribute page. 
  25. */ 
  26. public function include_script( ) { 
  27. if ( ! isset( $_REQUEST['page'] ) || ! in_array( $_REQUEST['page'], array( 'product_attributes' ) ) ) return; 
  28. ?> 
  29. <style> 
  30. .a3rev_panel_container { 
  31. border-top:1px dotted #666; 
  32. border-bottom:1px dotted #666; 
  33. margin-bottom:30px; 
  34. #col-container, #col-left { 
  35. overflow:visible !important; 
  36. div.form-field .chosen-container-single .chosen-results { 
  37. max-height:200px !important;  
  38. div.form-field .chosen-container-multi .chosen-results { 
  39. max-height:160px !important;  
  40. .a3rev_panel_container div.form-field label { 
  41. display: inline-block !important;  
  42. .a3rev_panel_container span.help_tip { 
  43. float:none !important;  
  44. .a3rev_panel_container .help_tip { 
  45. margin-right:-20px;  
  46. </style> 
  47. <?php 
  48. if ( isset( $_GET['edit'] ) && $_GET['edit'] > 0 ) { 
  49. $html_append = trim( $this->edit_feature_fields( $_GET['edit'] ) ); 
  50. ?> 
  51. <script> 
  52. jQuery(document).ready(function($) { 
  53. $(document).find('input[name="save_attribute"]').parent('p.submit').before('<?php echo $html_append; ?>'); 
  54. }); 
  55. </script> 
  56. <?php 
  57. } else { 
  58. $html_append = trim( $this->add_feature_fields() ); 
  59. ?>  
  60. <script> 
  61. jQuery(document).ready(function($) { 
  62. $(document).find('input[name="add_new_attribute"]').parent('p.submit').before('<?php echo $html_append; ?>'); 
  63. }); 
  64. </script> 
  65. <?php 
  66.  
  67. /** 
  68. * Compare Feature fields. 
  69. * @access public 
  70. * @return void 
  71. */ 
  72. public function add_feature_fields() { 
  73. ob_start(); 
  74. ?> 
  75. <div class="a3rev_panel_container"> 
  76. <div class="a3_wc_compare_plugin_meta_upgrade_area_box"> 
  77. <?php global $wc_compare_admin_init; $wc_compare_admin_init->upgrade_top_message(true); ?> 
  78. <h3><?php _e( 'Attribute Comparison Data', 'woocommerce-compare-products' ); ?></h3> 
  79. <input type="hidden" name="have_compare_feature_field" value="yes" /> 
  80. <div class="form-field"> 
  81. <label for="field_type"><?php _e('Select Categories', 'woocommerce-compare-products' ); ?></label>  
  82. <span class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("Attribute can be assigned to any Product Category that is activated for Product Comparisons. Attributes show on the comparison table as the Comparable Product Attributes.", 'woocommerce-compare-products' ) ?>"></span>  
  83. <div></div> 
  84. <?php 
  85. $compare_cats = WC_Compare_Functions::get_all_compare_cats(); 
  86. ?> 
  87. <select multiple="multiple" name="field_cats[]" data-placeholder="<?php _e('Select Compare Categories', 'woocommerce-compare-products' ); ?>" style="width:95%;" class="chzn-select"> 
  88. <?php 
  89. if ( is_array( $compare_cats ) && count( $compare_cats ) > 0 ) { 
  90. foreach ( $compare_cats as $cat ) { 
  91. ?> 
  92. <option value="<?php echo $cat->term_id; ?>"><?php echo esc_html( $cat->name ); ?></option> 
  93. <?php 
  94. ?> 
  95. </select> 
  96. </div> 
  97. <div class="form-field"> 
  98. <label for="field_type"><?php _e('Attribute and Terms Compare data Input type', 'woocommerce-compare-products' ); ?></label>  
  99. <span class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("Use these fields to determine how this Attribute with display its compare data. Text input fields are for adding custom compare data and ignore the Attribute Terms or set to show the Attributes Terms as single or multi select Compare data options that are quick and easy to set for each product.", 'woocommerce-compare-products' ) ?>"></span>  
  100. <div></div> 
  101. <select name="field_type" id="field_type" class="chzn-select" style="width:95%;"> 
  102. <?php 
  103. foreach ( $this->default_types as $type => $type_name) { 
  104. echo '<option value="'.$type.'">'.$type_name['name'].' - '.$type_name['description'].'</option>'; 
  105. ?> 
  106. </select> 
  107. </div> 
  108. <div class="form-field"> 
  109. <label for="field_unit"><?php _e('Attribute Unit of Measurement', 'woocommerce-compare-products' ); ?></label>  
  110. <span class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("e.g kgs, mm, lbs, cm, inches - the unit of measurement shows after the Attribute name in (brackets). If you leave this blank you will just see the Attribute name.", 'woocommerce-compare-products' ) ?>"></span>  
  111. <div></div> 
  112. <input type="text" name="field_unit" id="field_unit" value="" /> 
  113. </div> 
  114. </div> 
  115. </div> 
  116. <?php 
  117. $ouput = ob_get_clean(); 
  118. $ouput = addslashes( str_replace( array( "\r\n", "\r", "\n" ), "", $ouput ) ); 
  119. return $ouput; 
  120.  
  121. /** 
  122. * Edit Compare Feature field. 
  123. * @access public 
  124. * @param mixed $term Term (category) being edited 
  125. * @param mixed $taxonomy Taxonomy of the term being edited 
  126. */ 
  127. public function edit_feature_fields( $term_id ) { 
  128.  
  129. ob_start(); 
  130. ?> 
  131. <div class="a3rev_panel_container"> 
  132. <div class="a3_wc_compare_plugin_meta_upgrade_area_box"> 
  133. <?php global $wc_compare_admin_init; $wc_compare_admin_init->upgrade_top_message(true); ?> 
  134. <h3><?php _e( 'Attribute Comparison Data', 'woocommerce-compare-products' ); ?></h3> 
  135. <input type="hidden" name="have_compare_feature_field" value="yes" /> 
  136. <table class="form-table"> 
  137. <tbody> 
  138. <tr class="form-field"> 
  139. <th scope="row" valign="top"> 
  140. <div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("Attribute can be assigned to any Product Category that is activated for Product Comparisons. Attributes show on the comparison table as the Comparable Product Attributes.", 'woocommerce-compare-products' ) ?>"></div> 
  141. <label for="field_type"><?php _e('Select Categories', 'woocommerce-compare-products' ); ?></label>  
  142. </th> 
  143. <td> 
  144. <?php 
  145. $compare_cats = WC_Compare_Functions::get_all_compare_cats(); 
  146. ?> 
  147. <select multiple="multiple" name="field_cats[]" data-placeholder="<?php _e('Select Compare Categories', 'woocommerce-compare-products' ); ?>" style="width:95%;" class="chzn-select"> 
  148. <?php 
  149. if ( is_array( $compare_cats ) && count( $compare_cats ) > 0 ) { 
  150. foreach ( $compare_cats as $cat ) { 
  151. ?> 
  152. <option value="<?php echo $cat->term_id; ?>"><?php echo esc_html( $cat->name ); ?></option> 
  153. <?php 
  154. ?> 
  155. </select> 
  156. </td> 
  157. </tr> 
  158. <tr class="form-field"> 
  159. <th scope="row" valign="top"> 
  160. <div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("Use these fields to determine how this Attribute with display its compare data. Text input fields are for adding custom compare data and ignore the Attribute Terms or set to show the Attributes Terms as single or multi select Compare data options that are quick and easy to set for each product.", 'woocommerce-compare-products' ) ?>"></div> 
  161. <label for="field_type"><?php _e('Attribute and Terms Compare data Input type', 'woocommerce-compare-products' ); ?></label>  
  162. </th> 
  163. <td> 
  164. <select name="field_type" id="field_type" class="chzn-select" style="width:95%"> 
  165. <?php 
  166. foreach ( $this->default_types as $type => $type_name) { 
  167. ?> 
  168. <option value="<?php echo $type; ?>"><?php echo $type_name['name'].' - '.$type_name['description']; ?></option> 
  169. <?php 
  170. ?> 
  171. </select> 
  172. </td> 
  173. </tr> 
  174. <tr class="form-field"> 
  175. <th scope="row" valign="top"> 
  176. <div class="help_tip a3-plugin-ui-icon a3-plugin-ui-help-icon" data-tip="<?php _e("e.g kgs, mm, lbs, cm, inches - the unit of measurement shows after the Attribute name in (brackets). If you leave this blank you will just see the Attribute name.", 'woocommerce-compare-products' ) ?>"></div> 
  177. <label for="field_unit"><?php _e('Attribute Unit of Measurement', 'woocommerce-compare-products' ); ?></label>  
  178. </th> 
  179. <td> 
  180. <input type="text" name="field_unit" id="field_unit" value="" /> 
  181. </td> 
  182. </tr> 
  183. </tbody> 
  184. </table> 
  185. </div> 
  186. </div> 
  187. <?php 
  188. $ouput = ob_get_clean(); 
  189. $ouput = addslashes( str_replace( array( "\r\n", "\r", "\n" ), "", $ouput ) ); 
  190. return $ouput; 
  191.