attribute_name . '_pre_add_form', array( $this, 'product_attribute_description' ) ); } } // Maintain hierarchy of terms add_filter( 'wp_terms_checklist_args', array( $this, 'disable_checked_ontop' ) ); } /** * Order term when created (put in position 0). * * @param mixed $term_id * @param mixed $tt_id * @param string $taxonomy */ public function create_term( $term_id, $tt_id = '', $taxonomy = '' ) { if ( 'product_cat' != $taxonomy && ! taxonomy_is_product_attribute( $taxonomy ) ) { return; } $meta_name = taxonomy_is_product_attribute( $taxonomy ) ? 'order_' . esc_attr( $taxonomy ) : 'order'; update_woocommerce_term_meta( $term_id, $meta_name, 0 ); } /** * When a term is deleted, delete its meta. * * @param mixed $term_id */ public function delete_term( $term_id ) { global $wpdb; $term_id = absint( $term_id ); if ( $term_id && get_option( 'db_version' ) < 34370 ) { $wpdb->delete( $wpdb->woocommerce_termmeta, array( 'woocommerce_term_id' => $term_id ), array( '%d' ) ); } } /** * Category thumbnail fields. */ public function add_category_fields() { ?>
term_id, 'display_type', true ); $thumbnail_id = absint( get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ) ); if ( $thumbnail_id ) { $image = wp_get_attachment_thumb_url( $thumbnail_id ); } else { $image = wc_placeholder_img_src(); } ?>

Note: Deleting a term will remove it from all products and variations to which it has been assigned. Recreating a term will not automatically assign it back to products.', 'woocommerce' ) ); } /** * Thumbnail column added to category admin. * * @param mixed $columns * @return array */ public function product_cat_columns( $columns ) { $new_columns = array(); if ( isset( $columns['cb'] ) ) { $new_columns['cb'] = $columns['cb']; unset( $columns['cb'] ); } $new_columns['thumb'] = __( 'Image', 'woocommerce' ); return array_merge( $new_columns, $columns ); } /** * Thumbnail column value added to category admin. * * @param string $columns * @param string $column * @param int $id * @return array */ public function product_cat_column( $columns, $column, $id ) { if ( 'thumb' == $column ) { $thumbnail_id = get_woocommerce_term_meta( $id, 'thumbnail_id', true ); if ( $thumbnail_id ) { $image = wp_get_attachment_thumb_url( $thumbnail_id ); } else { $image = wc_placeholder_img_src(); } // Prevent esc_url from breaking spaces in urls for image embeds // Ref: https://core.trac.wordpress.org/ticket/23605 $image = str_replace( ' ', '%20', $image ); $columns .= '' . esc_attr__( 'Thumbnail', 'woocommerce' ) . ''; } return $columns; } /** * Maintain term hierarchy when editing a product. * * @param array $args * @return array */ public function disable_checked_ontop( $args ) { if ( ! empty( $args['taxonomy'] ) && 'product_cat' === $args['taxonomy'] ) { $args['checked_ontop'] = false; } return $args; } } new WC_Admin_Taxonomies();