Automattic\WooCommerce\Internal\Admin

CategoryLookup::on_edit()publicWC 1.0

When a product category gets edited, see if we need to sync the table.

Method of the class: CategoryLookup{}

No Hooks.

Return

null. Nothing (null).

Usage

$CategoryLookup = new CategoryLookup();
$CategoryLookup->on_edit( $category_id );
$category_id(int) (required)
Term ID being edited.

CategoryLookup::on_edit() code WC 8.7.0

public function on_edit( $category_id ) {
	global $wpdb;

	if ( ! isset( $this->edited_product_cats[ $category_id ] ) ) {
		return;
	}

	$category_object = get_term( $category_id, 'product_cat' );
	$prev_parent     = $this->edited_product_cats[ $category_id ];
	$new_parent      = $category_object->parent;

	// No edits - no need to modify relationships.
	if ( $prev_parent === $new_parent ) {
		return;
	}

	$this->delete( $category_id, $prev_parent );
	$this->update( $category_id );
}