Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
Utils::get_random_order_seed
Get the random order seed for a Product Collection.
Method of the class: Utils{}
No Hooks.
Returns
int. Random order seed.
Usage
$result = Utils::get_random_order_seed( $query_id, $query_context );
- $query_id(int) (required)
- Product Collection query ID.
- $query_context(array)
- Product Collection query context.
Default:array()
Changelog
| Since 11.0.0 | Introduced. |
Utils::get_random_order_seed() Utils::get random order seed code WC 11.1.2
public static function get_random_order_seed( $query_id, $query_context = array() ) {
$seed_context = array(
'blog_id' => get_current_blog_id(),
'queried_object_id' => get_queried_object_id(),
'query_id' => absint( $query_id ),
'rotation_key' => wp_date( 'Y-m-d' ),
'query' => $query_context,
);
$encoded_seed_context = wp_json_encode( $seed_context );
$seed_hash = (int) sprintf( '%u', crc32( is_string( $encoded_seed_context ) ? $encoded_seed_context : '' ) );
return ( $seed_hash % 2147483646 ) + 1;
}