wc_string_to_bool()
Converts a string (e.g. 'yes' or 'no') to a bool.
No Hooks.
Returns
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() wc string to bool code WC 10.6.2
function wc_string_to_bool( $string ) {
$string = $string ?? '';
return is_bool( $string ) ? $string : ( 'yes' === strtolower( $string ) || 1 === $string || 'true' === strtolower( $string ) || '1' === $string );
}