Automattic\WooCommerce\Internal\Admin
CategoryLookup::update
Updates lookup table data for a category by ID.
Метод класса: CategoryLookup{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->update( $category_id );
- $category_id(int) (обязательный)
- Category ID to update.
Код CategoryLookup::update() CategoryLookup::update WC 10.3.5
protected function update( $category_id ) {
global $wpdb;
$ancestors = get_ancestors( $category_id, 'product_cat', 'taxonomy' );
$children = get_term_children( $category_id, 'product_cat' );
$inserts = array();
$inserts[] = $this->get_insert_sql( $category_id, $category_id );
$children_ids = array_map( 'intval', array_unique( array_filter( $children ) ) );
foreach ( $ancestors as $ancestor ) {
$inserts[] = $this->get_insert_sql( $category_id, $ancestor );
foreach ( $children_ids as $child_category_id ) {
$inserts[] = $this->get_insert_sql( $child_category_id, $ancestor );
}
}
$insert_string = implode( ',', $inserts );
$wpdb->query( "INSERT IGNORE INTO $wpdb->wc_category_lookup (category_id, category_tree_id) VALUES {$insert_string}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}