' . wp_kses_post( $result->get_error_message() ) . '
'; } // Show admin interface. if ( ! empty( $_GET['edit'] ) ) { self::edit_attribute(); } else { self::add_attribute(); } } /** * Get and sanitize posted attribute data. * * @return array */ private static function get_posted_attribute() { $attribute = array( 'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( stripslashes( $_POST['attribute_label'] ) ) : '', 'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ) : '', 'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( $_POST['attribute_type'] ) : 'select', 'attribute_orderby' => isset( $_POST['attribute_orderby'] ) ? wc_clean( $_POST['attribute_orderby'] ) : '', 'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0, ); if ( empty( $attribute['attribute_type'] ) ) { $attribute['attribute_type'] = 'select'; } if ( empty( $attribute['attribute_label'] ) ) { $attribute['attribute_label'] = ucfirst( $attribute['attribute_name'] ); } if ( empty( $attribute['attribute_name'] ) ) { $attribute['attribute_name'] = wc_sanitize_taxonomy_name( $attribute['attribute_label'] ); } return $attribute; } /** * Add an attribute. * * @return bool|WP_Error */ private static function process_add_attribute() { check_admin_referer( 'woocommerce-add-new_attribute' ); $attribute = self::get_posted_attribute(); $args = array( 'name' => $attribute['attribute_label'], 'slug' => $attribute['attribute_name'], 'type' => $attribute['attribute_type'], 'order_by' => $attribute['attribute_orderby'], 'has_archives' => $attribute['attribute_public'], ); $id = wc_create_attribute( $args ); if ( is_wp_error( $id ) ) { return $id; } return true; } /** * Edit an attribute. * * @return bool|WP_Error */ private static function process_edit_attribute() { $attribute_id = absint( $_GET['edit'] ); check_admin_referer( 'woocommerce-save-attribute_' . $attribute_id ); $attribute = self::get_posted_attribute(); $args = array( 'name' => $attribute['attribute_label'], 'slug' => $attribute['attribute_name'], 'type' => $attribute['attribute_type'], 'order_by' => $attribute['attribute_orderby'], 'has_archives' => $attribute['attribute_public'], ); $id = wc_update_attribute( $attribute_id, $args ); if ( is_wp_error( $id ) ) { return $id; } echo '' . __( 'Attribute updated successfully', 'woocommerce' ) . '
' . esc_html__( 'Error: non-existing attribute ID.', 'woocommerce' ) . '
attribute_label ); ?> | attribute_name ); ?> | attribute_type ) ); ?> attribute_public ? esc_html__( '(Public)', 'woocommerce' ) : ''; ?> | attribute_orderby ) { case 'name' : esc_html_e( 'Name', 'woocommerce' ); break; case 'name_num' : esc_html_e( 'Name (numeric)', 'woocommerce' ); break; case 'id' : esc_html_e( 'Term ID', 'woocommerce' ); break; default: esc_html_e( 'Custom ordering', 'woocommerce' ); break; } ?> |
attribute_name );
if ( taxonomy_exists( $taxonomy ) ) {
if ( 'menu_order' === wc_attribute_orderby( $taxonomy ) ) {
$terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=ASC' );
} else {
$terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=false' );
}
switch ( $tax->attribute_orderby ) {
case 'name_num' :
usort( $terms, '_wc_get_product_terms_name_num_usort_callback' );
break;
case 'parent' :
usort( $terms, '_wc_get_product_terms_parent_usort_callback' );
break;
}
$terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) );
if ( $terms_string ) {
echo esc_html( $terms_string );
} else {
echo '–';
}
} else {
echo '–';
}
?>
|
|