WC_Admin_Attributes

WC_Admin_Attributes Class.

Defined (1)

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

/includes/admin/class-wc-admin-attributes.php  
  1. class WC_Admin_Attributes { 
  2.  
  3. /** 
  4. * Handles output of the attributes page in admin. 
  5. * Shows the created attributes and lets you add new ones or edit existing ones. 
  6. * The added attributes are stored in the database and can be used for layered navigation. 
  7. */ 
  8. public static function output() { 
  9. $result = ''; 
  10. $action = ''; 
  11.  
  12. // Action to perform: add, edit, delete or none 
  13. if ( ! empty( $_POST['add_new_attribute'] ) ) { 
  14. $action = 'add'; 
  15. } elseif ( ! empty( $_POST['save_attribute'] ) && ! empty( $_GET['edit'] ) ) { 
  16. $action = 'edit'; 
  17. } elseif ( ! empty( $_GET['delete'] ) ) { 
  18. $action = 'delete'; 
  19.  
  20. switch ( $action ) { 
  21. case 'add' : 
  22. $result = self::process_add_attribute(); 
  23. break; 
  24. case 'edit' : 
  25. $result = self::process_edit_attribute(); 
  26. break; 
  27. case 'delete' : 
  28. $result = self::process_delete_attribute(); 
  29. break; 
  30.  
  31. if ( is_wp_error( $result ) ) { 
  32. echo '<div id="woocommerce_errors" class="error"><p>' . wp_kses_post( $result->get_error_message() ) . '</p></div>'; 
  33.  
  34. // Show admin interface 
  35. if ( ! empty( $_GET['edit'] ) ) { 
  36. self::edit_attribute(); 
  37. } else { 
  38. self::add_attribute(); 
  39.  
  40. /** 
  41. * Get and sanitize posted attribute data. 
  42. * @return array 
  43. */ 
  44. private static function get_posted_attribute() { 
  45. $attribute = array( 
  46. 'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( stripslashes( $_POST['attribute_label'] ) ) : '',  
  47. 'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ) : '',  
  48. 'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( $_POST['attribute_type'] ) : 'select',  
  49. 'attribute_orderby' => isset( $_POST['attribute_orderby'] ) ? wc_clean( $_POST['attribute_orderby'] ) : '',  
  50. 'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0,  
  51. ); 
  52.  
  53. if ( empty( $attribute['attribute_type'] ) ) { 
  54. $attribute['attribute_type'] = 'select'; 
  55. if ( empty( $attribute['attribute_label'] ) ) { 
  56. $attribute['attribute_label'] = ucfirst( $attribute['attribute_name'] ); 
  57. if ( empty( $attribute['attribute_name'] ) ) { 
  58. $attribute['attribute_name'] = wc_sanitize_taxonomy_name( $attribute['attribute_label'] ); 
  59.  
  60. return $attribute; 
  61.  
  62. /** 
  63. * See if an attribute name is valid. 
  64. * @param string $attribute_name 
  65. * @return bool|WP_error result 
  66. */ 
  67. private static function valid_attribute_name( $attribute_name ) { 
  68. if ( strlen( $attribute_name ) > 28 ) { 
  69. /** translators: %s: attribute name */ 
  70. return new WP_Error( 'error', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), sanitize_title( $attribute_name ) ) ); 
  71. } elseif ( wc_check_if_attribute_name_is_reserved( $attribute_name ) ) { 
  72. /** translators: %s: attribute name */ 
  73. return new WP_Error( 'error', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), sanitize_title( $attribute_name ) ) ); 
  74.  
  75. return true; 
  76.  
  77. /** 
  78. * Add an attribute. 
  79. * @return bool|WP_Error 
  80. */ 
  81. private static function process_add_attribute() { 
  82. global $wpdb; 
  83. check_admin_referer( 'woocommerce-add-new_attribute' ); 
  84.  
  85. $attribute = self::get_posted_attribute(); 
  86.  
  87. if ( empty( $attribute['attribute_name'] ) || empty( $attribute['attribute_label'] ) ) { 
  88. return new WP_Error( 'error', __( 'Please, provide an attribute name and slug.', 'woocommerce' ) ); 
  89. } elseif ( ( $valid_attribute_name = self::valid_attribute_name( $attribute['attribute_name'] ) ) && is_wp_error( $valid_attribute_name ) ) { 
  90. return $valid_attribute_name; 
  91. } elseif ( taxonomy_exists( wc_attribute_taxonomy_name( $attribute['attribute_name'] ) ) ) { 
  92. /** translators: %s: attribute name */ 
  93. return new WP_Error( 'error', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), sanitize_title( $attribute['attribute_name'] ) ) ); 
  94.  
  95. $wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); 
  96.  
  97. do_action( 'woocommerce_attribute_added', $wpdb->insert_id, $attribute ); 
  98.  
  99. wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' ); 
  100. delete_transient( 'wc_attribute_taxonomies' ); 
  101.  
  102. return true; 
  103.  
  104. /** 
  105. * Edit an attribute. 
  106. * @return bool|WP_Error 
  107. */ 
  108. private static function process_edit_attribute() { 
  109. global $wpdb; 
  110. $attribute_id = absint( $_GET['edit'] ); 
  111. check_admin_referer( 'woocommerce-save-attribute_' . $attribute_id ); 
  112.  
  113. $attribute = self::get_posted_attribute(); 
  114.  
  115. if ( empty( $attribute['attribute_name'] ) || empty( $attribute['attribute_label'] ) ) { 
  116. return new WP_Error( 'error', __( 'Please, provide an attribute name and slug.', 'woocommerce' ) ); 
  117. } elseif ( ( $valid_attribute_name = self::valid_attribute_name( $attribute['attribute_name'] ) ) && is_wp_error( $valid_attribute_name ) ) { 
  118. return $valid_attribute_name; 
  119.  
  120. $taxonomy_exists = taxonomy_exists( wc_attribute_taxonomy_name( $attribute['attribute_name'] ) ); 
  121. $old_attribute_name = $wpdb->get_var( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ); 
  122. if ( $old_attribute_name != $attribute['attribute_name'] && wc_sanitize_taxonomy_name( $old_attribute_name ) != $attribute['attribute_name'] && $taxonomy_exists ) { 
  123. /** translators: %s: attribute name */ 
  124. return new WP_Error( 'error', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), sanitize_title( $attribute['attribute_name'] ) ) ); 
  125.  
  126. $wpdb->update( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute, array( 'attribute_id' => $attribute_id ) ); 
  127.  
  128. do_action( 'woocommerce_attribute_updated', $attribute_id, $attribute, $old_attribute_name ); 
  129.  
  130. if ( $old_attribute_name != $attribute['attribute_name'] && ! empty( $old_attribute_name ) ) { 
  131. // Update taxonomies in the wp term taxonomy table 
  132. $wpdb->update( 
  133. $wpdb->term_taxonomy,  
  134. array( 'taxonomy' => wc_attribute_taxonomy_name( $attribute['attribute_name'] ) ),  
  135. array( 'taxonomy' => 'pa_' . $old_attribute_name ) 
  136. ); 
  137.  
  138. // Update taxonomy ordering term meta 
  139. if ( get_option( 'db_version' ) < 34370 ) { 
  140. $wpdb->update( 
  141. $wpdb->prefix . 'woocommerce_termmeta',  
  142. array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute['attribute_name'] ) ),  
  143. array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) ) 
  144. ); 
  145. } else { 
  146. $wpdb->update( 
  147. $wpdb->termmeta,  
  148. array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute['attribute_name'] ) ),  
  149. array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) ) 
  150. ); 
  151.  
  152. // Update product attributes which use this taxonomy 
  153. $old_attribute_name_length = strlen( $old_attribute_name ) + 3; 
  154. $attribute_name_length = strlen( $attribute['attribute_name'] ) + 3; 
  155.  
  156. $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = REPLACE( meta_value, %s, %s ) WHERE meta_key = '_product_attributes'",  
  157. 's:' . $old_attribute_name_length . ':"pa_' . $old_attribute_name . '"',  
  158. 's:' . $attribute_name_length . ':"pa_' . $attribute['attribute_name'] . '"' 
  159. ) ); 
  160.  
  161. // Update variations which use this taxonomy 
  162. $wpdb->update( 
  163. $wpdb->postmeta,  
  164. array( 'meta_key' => 'attribute_pa_' . sanitize_title( $attribute['attribute_name'] ) ),  
  165. array( 'meta_key' => 'attribute_pa_' . sanitize_title( $old_attribute_name ) ) 
  166. ); 
  167.  
  168. echo '<div class="updated"><p>' . __( 'Attribute updated successfully', 'woocommerce' ) . '</p></div>'; 
  169.  
  170. wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' ); 
  171. delete_transient( 'wc_attribute_taxonomies' ); 
  172.  
  173. return true; 
  174.  
  175. /** 
  176. * Delete an attribute. 
  177. * @return bool 
  178. */ 
  179. private static function process_delete_attribute() { 
  180. global $wpdb; 
  181.  
  182. $attribute_id = absint( $_GET['delete'] ); 
  183.  
  184. check_admin_referer( 'woocommerce-delete-attribute_' . $attribute_id ); 
  185.  
  186. $attribute_name = $wpdb->get_var( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ); 
  187. $taxonomy = wc_attribute_taxonomy_name( $attribute_name ); 
  188.  
  189. do_action( 'woocommerce_before_attribute_delete', $attribute_id, $attribute_name, $taxonomy ); 
  190.  
  191. if ( $attribute_name && $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ) ) { 
  192. if ( taxonomy_exists( $taxonomy ) ) { 
  193. $terms = get_terms( $taxonomy, 'orderby=name&hide_empty=0' ); 
  194. foreach ( $terms as $term ) { 
  195. wp_delete_term( $term->term_id, $taxonomy ); 
  196.  
  197. do_action( 'woocommerce_attribute_deleted', $attribute_id, $attribute_name, $taxonomy ); 
  198. delete_transient( 'wc_attribute_taxonomies' ); 
  199. return true; 
  200.  
  201. return false; 
  202.  
  203. /** 
  204. * Edit Attribute admin panel. 
  205. * Shows the interface for changing an attributes type between select and text. 
  206. */ 
  207. public static function edit_attribute() { 
  208. global $wpdb; 
  209.  
  210. $edit = absint( $_GET['edit'] ); 
  211.  
  212. $attribute_to_edit = $wpdb->get_row( "SELECT attribute_type, attribute_label, attribute_name, attribute_orderby, attribute_public FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$edit'" ); 
  213.  
  214. ?> 
  215. <div class="wrap woocommerce"> 
  216. <h1><?php _e( 'Edit attribute', 'woocommerce' ) ?></h1> 
  217.  
  218. <?php 
  219.  
  220. if ( ! $attribute_to_edit ) { 
  221. echo '<div id="woocommerce_errors" class="error"><p>' . __( 'Error: non-existing attribute ID.', 'woocommerce' ) . '</p></div>'; 
  222. } else { 
  223. $att_type = $attribute_to_edit->attribute_type; 
  224. $att_label = $attribute_to_edit->attribute_label; 
  225. $att_name = $attribute_to_edit->attribute_name; 
  226. $att_orderby = $attribute_to_edit->attribute_orderby; 
  227. $att_public = $attribute_to_edit->attribute_public; 
  228.  
  229. ?> 
  230.  
  231. <form action="edit.php?post_type=product&page=product_attributes&edit=<?php echo absint( $edit ); ?>" method="post"> 
  232. <table class="form-table"> 
  233. <tbody> 
  234. <?php do_action( 'woocommerce_before_edit_attribute_fields' ); ?> 
  235. <tr class="form-field form-required"> 
  236. <th scope="row" valign="top"> 
  237. <label for="attribute_label"><?php _e( 'Name', 'woocommerce' ); ?></label> 
  238. </th> 
  239. <td> 
  240. <input name="attribute_label" id="attribute_label" type="text" value="<?php echo esc_attr( $att_label ); ?>" /> 
  241. <p class="description"><?php _e( 'Name for the attribute (shown on the front-end).', 'woocommerce' ); ?></p> 
  242. </td> 
  243. </tr> 
  244. <tr class="form-field form-required"> 
  245. <th scope="row" valign="top"> 
  246. <label for="attribute_name"><?php _e( 'Slug', 'woocommerce' ); ?></label> 
  247. </th> 
  248. <td> 
  249. <input name="attribute_name" id="attribute_name" type="text" value="<?php echo esc_attr( $att_name ); ?>" maxlength="28" /> 
  250. <p class="description"><?php _e( 'Unique slug/reference for the attribute; must be no more than 28 characters.', 'woocommerce' ); ?></p> 
  251. </td> 
  252. </tr> 
  253. <tr class="form-field form-required"> 
  254. <th scope="row" valign="top"> 
  255. <label for="attribute_public"><?php _e( 'Enable archives?', 'woocommerce' ); ?></label> 
  256. </th> 
  257. <td> 
  258. <input name="attribute_public" id="attribute_public" type="checkbox" value="1" <?php checked( $att_public, 1 ); ?> /> 
  259. <p class="description"><?php _e( 'Enable this if you want this attribute to have product archives in your store.', 'woocommerce' ); ?></p> 
  260. </td> 
  261. </tr> 
  262. <tr class="form-field form-required"> 
  263. <th scope="row" valign="top"> 
  264. <label for="attribute_type"><?php _e( 'Type', 'woocommerce' ); ?></label> 
  265. </th> 
  266. <td> 
  267. <select name="attribute_type" id="attribute_type"> 
  268. <?php foreach ( wc_get_attribute_types() as $key => $value ) : ?> 
  269. <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $att_type, $key ); ?>><?php echo esc_attr( $value ); ?></option> 
  270. <?php endforeach; ?> 
  271.  
  272. <?php 
  273. /** 
  274. * Deprecated action in favor of product_attributes_type_selector filter. 
  275. * @deprecated 2.4.0 
  276. */ 
  277. do_action( 'woocommerce_admin_attribute_types' ); 
  278. ?> 
  279. </select> 
  280. <p class="description"><?php _e( 'Determines how you select attributes for products. Under admin panel -> products -> product data -> attributes -> values, <strong>Text</strong> allows manual entry whereas <strong>select</strong> allows pre-configured terms in a drop-down list.', 'woocommerce' ); ?></p> 
  281. </td> 
  282. </tr> 
  283. <tr class="form-field form-required"> 
  284. <th scope="row" valign="top"> 
  285. <label for="attribute_orderby"><?php _e( 'Default sort order', 'woocommerce' ); ?></label> 
  286. </th> 
  287. <td> 
  288. <select name="attribute_orderby" id="attribute_orderby"> 
  289. <option value="menu_order" <?php selected( $att_orderby, 'menu_order' ); ?>><?php _e( 'Custom ordering', 'woocommerce' ); ?></option> 
  290. <option value="name" <?php selected( $att_orderby, 'name' ); ?>><?php _e( 'Name', 'woocommerce' ); ?></option> 
  291. <option value="name_num" <?php selected( $att_orderby, 'name_num' ); ?>><?php _e( 'Name (numeric)', 'woocommerce' ); ?></option> 
  292. <option value="id" <?php selected( $att_orderby, 'id' ); ?>><?php _e( 'Term ID', 'woocommerce' ); ?></option> 
  293. </select> 
  294. <p class="description"><?php _e( 'Determines the sort order of the terms on the frontend shop product pages. If using custom ordering, you can drag and drop the terms in this attribute.', 'woocommerce' ); ?></p> 
  295. </td> 
  296. </tr> 
  297. <?php do_action( 'woocommerce_after_edit_attribute_fields' ) ?> 
  298. </tbody> 
  299. </table> 
  300. <p class="submit"><input type="submit" name="save_attribute" id="submit" class="button-primary" value="<?php esc_attr_e( 'Update', 'woocommerce' ); ?>"></p> 
  301. <?php wp_nonce_field( 'woocommerce-save-attribute_' . $edit ); ?> 
  302. </form> 
  303. <?php } ?> 
  304. </div> 
  305. <?php 
  306.  
  307. /** 
  308. * Add Attribute admin panel. 
  309. * Shows the interface for adding new attributes. 
  310. */ 
  311. public static function add_attribute() { 
  312. ?> 
  313. <div class="wrap woocommerce"> 
  314. <h1><?php echo get_admin_page_title(); ?></h1> 
  315.  
  316. <br class="clear" /> 
  317. <div id="col-container"> 
  318. <div id="col-right"> 
  319. <div class="col-wrap"> 
  320. <table class="widefat attributes-table wp-list-table ui-sortable" style="width:100%"> 
  321. <thead> 
  322. <tr> 
  323. <th scope="col"><?php _e( 'Name', 'woocommerce' ); ?></th> 
  324. <th scope="col"><?php _e( 'Slug', 'woocommerce' ); ?></th> 
  325. <th scope="col"><?php _e( 'Type', 'woocommerce' ); ?></th> 
  326. <th scope="col"><?php _e( 'Order by', 'woocommerce' ); ?></th> 
  327. <th scope="col"><?php _e( 'Terms', 'woocommerce' ); ?></th> 
  328. </tr> 
  329. </thead> 
  330. <tbody> 
  331. <?php 
  332. if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) : 
  333. foreach ( $attribute_taxonomies as $tax ) : 
  334. ?><tr> 
  335. <td> 
  336. <strong><a href="edit-tags.php?taxonomy=<?php echo esc_html( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&post_type=product"><?php echo esc_html( $tax->attribute_label ); ?></a></strong> 
  337.  
  338. <div class="row-actions"><span class="edit"><a href="<?php echo esc_url( add_query_arg( 'edit', $tax->attribute_id, 'edit.php?post_type=product&page=product_attributes' ) ); ?>"><?php _e( 'Edit', 'woocommerce' ); ?></a> | </span><span class="delete"><a class="delete" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'delete', $tax->attribute_id, 'edit.php?post_type=product&page=product_attributes' ), 'woocommerce-delete-attribute_' . $tax->attribute_id ) ); ?>"><?php _e( 'Delete', 'woocommerce' ); ?></a></span></div> 
  339. </td> 
  340. <td><?php echo esc_html( $tax->attribute_name ); ?></td> 
  341. <td><?php echo esc_html( wc_get_attribute_type_label( $tax->attribute_type ) ); ?> <?php echo $tax->attribute_public ? __( '(Public)', 'woocommerce' ) : ''; ?></td> 
  342. <td><?php 
  343. switch ( $tax->attribute_orderby ) { 
  344. case 'name' : 
  345. _e( 'Name', 'woocommerce' ); 
  346. break; 
  347. case 'name_num' : 
  348. _e( 'Name (numeric)', 'woocommerce' ); 
  349. break; 
  350. case 'id' : 
  351. _e( 'Term ID', 'woocommerce' ); 
  352. break; 
  353. default: 
  354. _e( 'Custom ordering', 'woocommerce' ); 
  355. break; 
  356. ?></td> 
  357. <td class="attribute-terms"><?php 
  358. $taxonomy = wc_attribute_taxonomy_name( $tax->attribute_name ); 
  359.  
  360. if ( taxonomy_exists( $taxonomy ) ) { 
  361. if ( 'menu_order' === wc_attribute_orderby( $taxonomy ) ) { 
  362. $terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=ASC' ); 
  363. } else { 
  364. $terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=false' ); 
  365.  
  366. switch ( $tax->attribute_orderby ) { 
  367. case 'name_num' : 
  368. usort( $terms, '_wc_get_product_terms_name_num_usort_callback' ); 
  369. break; 
  370. case 'parent' : 
  371. usort( $terms, '_wc_get_product_terms_parent_usort_callback' ); 
  372. break; 
  373.  
  374. $terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) ); 
  375. if ( $terms_string ) { 
  376. echo $terms_string; 
  377. } else { 
  378. echo '<span class="na">–</span>'; 
  379. } else { 
  380. echo '<span class="na">–</span>'; 
  381. ?> 
  382. <br /><a href="edit-tags.php?taxonomy=<?php echo esc_html( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&post_type=product" class="configure-terms"><?php _e( 'Configure terms', 'woocommerce' ); ?></a> 
  383. </td> 
  384. </tr><?php 
  385. endforeach; 
  386. else : 
  387. ?><tr><td colspan="6"><?php _e( 'No attributes currently exist.', 'woocommerce' ) ?></td></tr><?php 
  388. endif; 
  389. ?> 
  390. </tbody> 
  391. </table> 
  392. </div> 
  393. </div> 
  394. <div id="col-left"> 
  395. <div class="col-wrap"> 
  396. <div class="form-wrap"> 
  397. <h2><?php _e( 'Add new attribute', 'woocommerce' ); ?></h2> 
  398. <p><?php _e( 'Attributes let you define extra product data, such as size or color. You can use these attributes in the shop sidebar using the "layered nav" widgets. Please note: you cannot rename an attribute later on.', 'woocommerce' ); ?></p> 
  399. <form action="edit.php?post_type=product&page=product_attributes" method="post"> 
  400. <?php do_action( 'woocommerce_before_add_attribute_fields' ) ?> 
  401.  
  402. <div class="form-field"> 
  403. <label for="attribute_label"><?php _e( 'Name', 'woocommerce' ); ?></label> 
  404. <input name="attribute_label" id="attribute_label" type="text" value="" /> 
  405. <p class="description"><?php _e( 'Name for the attribute (shown on the front-end).', 'woocommerce' ); ?></p> 
  406. </div> 
  407.  
  408. <div class="form-field"> 
  409. <label for="attribute_name"><?php _e( 'Slug', 'woocommerce' ); ?></label> 
  410. <input name="attribute_name" id="attribute_name" type="text" value="" maxlength="28" /> 
  411. <p class="description"><?php _e( 'Unique slug/reference for the attribute; must be no more than 28 characters.', 'woocommerce' ); ?></p> 
  412. </div> 
  413.  
  414. <div class="form-field"> 
  415. <label for="attribute_public"><input name="attribute_public" id="attribute_public" type="checkbox" value="1" /> <?php _e( 'Enable Archives?', 'woocommerce' ); ?></label> 
  416.  
  417. <p class="description"><?php _e( 'Enable this if you want this attribute to have product archives in your store.', 'woocommerce' ); ?></p> 
  418. </div> 
  419.  
  420. <div class="form-field"> 
  421. <label for="attribute_type"><?php _e( 'Type', 'woocommerce' ); ?></label> 
  422. <select name="attribute_type" id="attribute_type"> 
  423. <?php foreach ( wc_get_attribute_types() as $key => $value ) : ?> 
  424. <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $value ); ?></option> 
  425. <?php endforeach; ?> 
  426.  
  427. <?php 
  428.  
  429. /** 
  430. * Deprecated action in favor of product_attributes_type_selector filter. 
  431. * @deprecated 2.4.0 
  432. */ 
  433. do_action( 'woocommerce_admin_attribute_types' ); 
  434. ?> 
  435. </select> 
  436. <p class="description"><?php _e( 'Determines how you select attributes for products. Under admin panel -> products -> product data -> attributes -> values, <strong>Text</strong> allows manual entry whereas <strong>select</strong> allows pre-configured terms in a drop-down list.', 'woocommerce' ); ?></p> 
  437. </div> 
  438.  
  439. <div class="form-field"> 
  440. <label for="attribute_orderby"><?php _e( 'Default sort order', 'woocommerce' ); ?></label> 
  441. <select name="attribute_orderby" id="attribute_orderby"> 
  442. <option value="menu_order"><?php _e( 'Custom ordering', 'woocommerce' ); ?></option> 
  443. <option value="name"><?php _e( 'Name', 'woocommerce' ); ?></option> 
  444. <option value="name_num"><?php _e( 'Name (numeric)', 'woocommerce' ); ?></option> 
  445. <option value="id"><?php _e( 'Term ID', 'woocommerce' ); ?></option> 
  446. </select> 
  447. <p class="description"><?php _e( 'Determines the sort order of the terms on the frontend shop product pages. If using custom ordering, you can drag and drop the terms in this attribute.', 'woocommerce' ); ?></p> 
  448. </div> 
  449.  
  450. <?php do_action( 'woocommerce_after_add_attribute_fields' ) ?> 
  451.  
  452. <p class="submit"><input type="submit" name="add_new_attribute" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Add attribute', 'woocommerce' ); ?>"></p> 
  453. <?php wp_nonce_field( 'woocommerce-add-new_attribute' ); ?> 
  454. </form> 
  455. </div> 
  456. </div> 
  457. </div> 
  458. </div> 
  459. <script type="text/javascript"> 
  460. /* <![CDATA[ */ 
  461.  
  462. jQuery( 'a.delete' ).click( function() { 
  463. if ( window.confirm( '<?php _e( "Are you sure you want to delete this attribute?", "woocommerce" ); ?>' ) ) { 
  464. return true; 
  465. return false; 
  466. }); 
  467.  
  468. /* ]]> */ 
  469. </script> 
  470. </div> 
  471. <?php