WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Admin

CategoryLookup::delete() protected WC 1.0

Delete lookup table data from a tree.

{} It's a method of the class: CategoryLookup{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->delete( $category_id, $category_tree_id );
$category_id(int) (required)
Category ID to delete.
$category_tree_id(int) (required)
Tree to delete from.

Code of CategoryLookup::delete() WC 5.6.0

protected function delete( $category_id, $category_tree_id ) {
	global $wpdb;

	if ( ! $category_tree_id ) {
		return;
	}

	$ancestors   = get_ancestors( $category_tree_id, 'product_cat', 'taxonomy' );
	$ancestors[] = $category_tree_id;
	$children    = get_term_children( $category_id, 'product_cat' );
	$children[]  = $category_id;
	$id_list     = implode( ',', array_map( 'intval', array_unique( array_filter( $children ) ) ) );

	foreach ( $ancestors as $ancestor ) {
		$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->wc_category_lookup WHERE category_tree_id = %d AND category_id IN ({$id_list})", $ancestor ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	}
}