Automattic\WooCommerce\Internal\Products
ProductsOrderingMoveService::has_moved
Determines whether the product's position needs updating.
Method of the class: ProductsOrderingMoveService{}
No Hooks.
Returns
bool.
Usage
// private - for code of main (parent) class only $result = $this->has_moved( $anchor_positions, $previous_id, $product_id, $next_id ): bool;
- $anchor_positions(array<int,int>) (required)
- Map of product ID → current menu_order, ordered by menu_order ASC.
- $previous_id(int) (required)
- ID of the product before the target position, or 0 for start.
- $product_id(int) (required)
- ID of the product being repositioned.
- $next_id(int) (required)
- ID of the product after the target position, or 0 for end.
ProductsOrderingMoveService::has_moved() ProductsOrderingMoveService::has moved code WC 11.3.0
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;
}