wc_string_to_bool()WC 3.0.0

Converts a string (e.g. 'yes' or 'no') to a bool.

No Hooks.

Return

true|false.

Usage

wc_string_to_bool( $string );
$string(string|true|false) (required)
String to convert. If a bool is passed it will be returned as-is.

Changelog

Since 3.0.0 Introduced.

wc_string_to_bool() code WC 8.7.0

function wc_string_to_bool( $string ) {
	$string = $string ?? '';
	return is_bool( $string ) ? $string : ( 'yes' === strtolower( $string ) || 1 === $string || 'true' === strtolower( $string ) || '1' === $string );
}