Automattic\WooCommerce\Internal\Products
ProductsOrderingMoveService::has_moved
Determines whether the product's position needs updating.
Метод класса: ProductsOrderingMoveService{}
Хуков нет.
Возвращает
bool.
Использование
// private - только в коде основоного (родительского) класса $result = $this->has_moved( $anchor_positions, $previous_id, $product_id, $next_id ): bool;
- $anchor_positions(array<int,int>) (обязательный)
- Map of product ID → current menu_order, ordered by menu_order ASC.
- $previous_id(int) (обязательный)
- ID of the product before the target position, or 0 for start.
- $product_id(int) (обязательный)
- ID of the product being repositioned.
- $next_id(int) (обязательный)
- ID of the product after the target position, or 0 for end.
Код ProductsOrderingMoveService::has_moved() ProductsOrderingMoveService::has moved WC 11.2.2
private function has_moved( array $anchor_positions, int $previous_id, int $product_id, int $next_id ): bool {
// Compare DB ordering (array keys sorted by menu_order) against the requested ordering (filtering out 0 pseudo-IDs).
$has_moved = array_keys( $anchor_positions ) !== array_values( array_filter( array( $previous_id, $product_id, $next_id ) ) );
if ( $has_moved ) {
return true;
}
// Unindexed (position 0) or colliding (duplicate positions) anchors always need work.
$needs_reindexing = in_array( 0, $anchor_positions, true ) || count( array_unique( $anchor_positions ) ) !== count( $anchor_positions );
if ( $needs_reindexing ) {
return true;
}
return false;
}