WC_Meta_Box_Product_Categories::output()public staticWC 1.0

Output the metabox.

Method of the class: WC_Meta_Box_Product_Categories{}

Return

null. Nothing (null).

Usage

$result = WC_Meta_Box_Product_Categories::output( $post, $box );
$post(WP_Post) (required)
Current post object.
$box(array) (required)

Categories meta box arguments.

  • id(string)
    Meta box 'id' attribute.

  • title(string)
    Meta box title.

  • callback(callable)
    Meta box display callback.

  • args(array)
    Extra meta box arguments.

    • taxonomy(string)
      Taxonomy.
      Default: 'category'

WC_Meta_Box_Product_Categories::output() code WC 9.7.1

<?php
public static function output( $post, $box ) {
	$categories_count = (int) wp_count_terms( 'product_cat' );

	/**
	 * Filters the category metabox search threshold, for when to render the typeahead field.
	 *
	 * @since 7.6.0
	 *
	 * @param number $threshold The default threshold.
	 * @returns number The threshold that will be used.
	 */
	if ( $categories_count <= apply_filters( 'woocommerce_product_category_metabox_search_threshold', 5 ) && function_exists( 'post_categories_meta_box' ) ) {
		return post_categories_meta_box( $post, $box );
	}

	$defaults = array( 'taxonomy' => 'category' );
	if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
		$args = array();
	} else {
		$args = $box['args'];
	}
	$parsed_args         = wp_parse_args( $args, $defaults );
	$tax_name            = $parsed_args['taxonomy'];
	$selected_categories = wp_get_object_terms( $post->ID, 'product_cat' );
	?>
	<div id="taxonomy-<?php echo esc_attr( $tax_name ); ?>-metabox"></div>
	<?php foreach ( (array) $selected_categories as $term ) { ?>
		<input
			type="hidden"
			value="<?php echo esc_attr( $term->term_id ); ?>"
			name="tax_input[<?php esc_attr( $tax_name ); ?>][]"
			data-name="<?php echo esc_attr( $term->name ); ?>"
		/>
		<?php
	}
}