= 30 ) echo '

' . sprintf( __( 'Slug %s is too long', 'woocommerce' ), sanitize_title( $attribute_name ) ) . '

'; if ( $attribute_name && strlen( $attribute_name ) < 30 && $attribute_type && ! taxonomy_exists( $woocommerce->attribute_taxonomy_name( $attribute_name ) ) ) { $wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $attribute_name, 'attribute_label' => $attribute_label, 'attribute_type' => $attribute_type, 'attribute_orderby' => $attribute_orderby ) ); delete_transient( 'wc_attribute_taxonomies' ); wp_safe_redirect( get_admin_url() . 'edit.php?post_type=product&page=woocommerce_attributes' ); exit; } } elseif ( ! empty( $_POST['save_attribute'] ) && ! empty( $_GET['edit'] ) ) { $edit = absint( $_GET['edit'] ); check_admin_referer( 'woocommerce-save-attribute_' . $edit ); $attribute_name = woocommerce_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ); $attribute_type = esc_attr( $_POST['attribute_type'] ); $attribute_label = esc_attr( $_POST['attribute_label'] ); $attribute_orderby = esc_attr( $_POST['attribute_orderby'] ); if ( ! $attribute_label ) $attribute_label = ucwords( $attribute_name ); if ( ! $attribute_name ) $attribute_name = sanitize_title( $attribute_label ); $old_attribute_name = woocommerce_sanitize_taxonomy_name( $wpdb->get_var( "SELECT attribute_name FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = $edit" ) ); if ( $old_attribute_name != $attribute_name && taxonomy_exists( $woocommerce->attribute_taxonomy_name( $attribute_name ) ) ) { echo '

' . __( 'Taxonomy exists - please change the slug', 'woocommerce' ) . '

'; } elseif ( $attribute_name && strlen( $attribute_name ) < 30 && $attribute_type ) { $wpdb->update( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $attribute_name, 'attribute_label' => $attribute_label, 'attribute_type' => $attribute_type, 'attribute_orderby' => $attribute_orderby ), array( 'attribute_id' => $edit ) ); if ( $old_attribute_name != $attribute_name && ! empty( $old_attribute_name ) ) { // Update taxonomies in the wp term taxonomy table $wpdb->update( $wpdb->term_taxonomy, array( 'taxonomy' => $woocommerce->attribute_taxonomy_name( $attribute_name ) ), array( 'taxonomy' => $woocommerce->attribute_taxonomy_name( $old_attribute_name ) ) ); // Update taxonomy ordering term meta $wpdb->update( $wpdb->prefix . "woocommerce_termmeta", array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute_name ) ), array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) ) ); // Update product attributes which use this taxonomy $old_attribute_name_length = strlen($old_attribute_name) + 3; $attribute_name_length = strlen($attribute_name) + 3; $wpdb->query( " UPDATE {$wpdb->postmeta} SET meta_value = replace( meta_value, 's:{$old_attribute_name_length}:\"pa_{$old_attribute_name}\"', 's:{$attribute_name_length}:\"pa_{$attribute_name}\"' ) WHERE meta_key = '_product_attributes'" ); // Update variations which use this taxonomy $wpdb->update( $wpdb->postmeta, array( 'meta_key' => 'attribute_pa_' . sanitize_title( $attribute_name ) ), array( 'meta_key' => 'attribute_pa_' . sanitize_title( $old_attribute_name ) ) ); } delete_transient( 'wc_attribute_taxonomies' ); wp_safe_redirect( get_admin_url() . 'edit.php?post_type=product&page=woocommerce_attributes' ); exit; } } elseif ( ! empty( $_GET['delete'] ) ) { $delete = absint( $_GET['delete'] ); check_admin_referer( 'woocommerce-delete-attribute_' . $delete ); $att_name = $wpdb->get_var( "SELECT attribute_name FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = $delete" ); if ( $att_name && $wpdb->query( "DELETE FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = $delete" ) ) { $taxonomy = $woocommerce->attribute_taxonomy_name( $att_name ); if ( taxonomy_exists( $taxonomy ) ) { $terms = get_terms( $taxonomy, 'orderby=name&hide_empty=0'); foreach ( $terms as $term ) wp_delete_term( $term->term_id, $taxonomy ); } delete_transient( 'wc_attribute_taxonomies' ); wp_safe_redirect( get_admin_url() . 'edit.php?post_type=product&page=woocommerce_attributes' ); exit; } } if ( ! empty( $_GET['edit'] ) && $_GET['edit'] > 0 ) woocommerce_edit_attribute(); else woocommerce_add_attribute(); } /** * Edit Attribute admin panel * * Shows the interface for changing an attributes type between select and text * * @access public * @return void */ function woocommerce_edit_attribute() { global $wpdb; $edit = absint( $_GET['edit'] ); $attribute_to_edit = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$edit'"); $att_type = $attribute_to_edit->attribute_type; $att_label = $attribute_to_edit->attribute_label; $att_name = $attribute_to_edit->attribute_name; $att_orderby = $attribute_to_edit->attribute_orderby; ?>

Text allows manual entry via the product page, whereas select attribute terms can be defined from this section. If you plan on using an attribute for variations use select.', 'woocommerce' ); ?>



get_attribute_taxonomies(); if ( $attribute_taxonomies ) : foreach ($attribute_taxonomies as $tax) : ?>
attribute_label ); ?>
|
attribute_name ); ?> attribute_type ) ); ?> attribute_orderby ) { case 'name' : _e( 'Name', 'woocommerce' ); break; case 'id' : _e( 'Term ID', 'woocommerce' ); break; default: _e( 'Custom ordering', 'woocommerce' ); break; } ?> attribute_taxonomy_name($tax->attribute_name))) : $terms_array = array(); $terms = get_terms( $woocommerce->attribute_taxonomy_name($tax->attribute_name), 'orderby=name&hide_empty=0' ); if ($terms) : foreach ($terms as $term) : $terms_array[] = $term->name; endforeach; echo implode(', ', $terms_array); else : echo ''; endif; else : echo ''; endif; ?>

Text allows manual entry via the product page, whereas select attribute terms can be defined from this section. If you plan on using an attribute for variations use select.', 'woocommerce' ); ?>