Automattic\WooCommerce\Internal\Admin\Reports

HposLegacyOrderReportQueryBuilder::prepare_predicate_value │ private │ WC 1.0

Prepare the right-hand side of a predicate (e.g. = '5' or IN ('a','b')).

Used by both the where (value / operator) and where_meta (meta_value / operator) builders.

Method of the class: HposLegacyOrderReportQueryBuilder{}

No Hooks.

Returns

string. SQL fragment, or empty string when no predicate is emitted.

Usage

// private - for code of main (parent) class only
$result = $this->prepare_predicate_value( $value, $value_key ): string;
$value(array) (required)
A where or where_meta row.
$value_key(string) (required)
The array key holding the RHS value (value or meta_value).

HposLegacyOrderReportQueryBuilder::prepare_predicate_value() code WC 11.2.1

private function prepare_predicate_value( array $value, string $value_key ): string {
	global $wpdb;
	$op_lc = strtolower( $value['operator'] );
	$rhs   = $value[ $value_key ] ?? '';

	if ( 'in' === $op_lc || 'not in' === $op_lc ) {
		if ( ! empty( $rhs ) && ! is_array( $rhs ) ) {
			$rhs = (array) $rhs;
		}
		if ( empty( $rhs ) ) {
			return '';
		}
		$formats = implode( ', ', array_fill( 0, count( $rhs ), '%s' ) );
		return $value['operator'] . ' (' . $wpdb->prepare( $formats, $rhs ) . ')'; // @phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
	}

	return $value['operator'] . ' ' . $wpdb->prepare( '%s', $rhs );
}