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(); } ?>
name; ?>


' . esc_html( $category_name ) . '' ); ?>


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' ); $columns = array_merge( $new_columns, $columns ); $columns['handle'] = ''; return $columns; } /** * Adjust row actions. * * @param array $actions Array of actions. * @param object $term Term object. * @return array */ public function product_cat_row_actions( $actions = array(), $term ) { $default_category_id = absint( get_option( 'default_product_cat', 0 ) ); if ( $default_category_id !== $term->term_id && current_user_can( 'edit_term', $term->term_id ) ) { $actions['make_default'] = sprintf( '%s', wp_nonce_url( 'edit-tags.php?action=make_default&taxonomy=product_cat&tag_ID=' . absint( $term->term_id ), 'make_default_' . absint( $term->term_id ) ), /* translators: %s: taxonomy term name */ esc_attr( sprintf( __( 'Make “%s” the default category', 'woocommerce' ), $term->name ) ), __( 'Make default', 'woocommerce' ) ); } return $actions; } /** * Handle custom row actions. */ public function handle_product_cat_row_actions() { if ( isset( $_GET['action'], $_GET['tag_ID'], $_GET['_wpnonce'] ) && 'make_default' === $_GET['action'] ) { $make_default_id = absint( $_GET['tag_ID'] ); if ( wp_verify_nonce( $_GET['_wpnonce'], 'make_default_' . $make_default_id ) && current_user_can( 'edit_term', $make_default_id ) ) { update_option( 'default_product_cat', $make_default_id ); } } } /** * Thumbnail column value added to category admin. * * @param string $columns * @param string $column * @param int $id * * @return string */ public function product_cat_column( $columns, $column, $id ) { if ( 'thumb' === $column ) { // Prepend tooltip for default category. $default_category_id = absint( get_option( 'default_product_cat', 0 ) ); if ( $default_category_id === $id ) { $columns .= wc_help_tip( __( 'This is the default category and it cannot be deleted. It will be automatically assigned to products with no category.', 'woocommerce' ) ); } $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' ) . ''; } if ( 'handle' === $column ) { $columns .= ''; } 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();