Namespace #
LevCharity\Helpers\Helper
Overview #
The Main Helper class with static methods that you can use everywhere
Properties #
Name | Type | Visibility | Usage | Description |
---|---|---|---|---|
$property | string[] | private | static (or leave empty) | Some description here |
Methods #
convertMetaKeyToTitle #
Converts a meta key (slug) into a human-readable title by removing a prefix and transforming it into a title-case format.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$slug | string | n/a | The slug to convert. |
Examples:
LevCharity\Helpers\Helper::convertMetaKeyToTitle('levcharity_custom_field_example_slug');
formatToCamelCase #
Converts a string into camelCase format. Non-alphanumeric characters are replaced by spaces, and words are capitalized, except the first word.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$string | string | n/a | The string to format. |
Examples:
LevCharity\Helpers\Helper::formatToCamelCase('example_string_to_convert');
convertYearToHebrew #
Converts a Gregorian year to its corresponding Hebrew year. Returns null if the year is invalid.
Returns: int|null
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$year | int | n/a | The Gregorian year to convert. |
Examples:
LevCharity\Helpers\Helper::convertYearToHebrew(2025);
mergeMultipleObjects #
Merges multiple objects into one by copying the properties of each object to the first object.
Returns: object
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$objects | array | n/a | An array of objects to merge. |
Examples:
LevCharity\Helpers\Helper::mergeMultipleObjects([$object1, $object2]);
getApprovalInfoByHash #
Fetches the approval information based on a provided hash. Returns an empty array if no information is found.
Returns: array
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$hash | string | n/a | The hash used to find approval information. |
Examples:
LevCharity\Helpers\Helper::getApprovalInfoByHash('someHash');
generateHashAndSaveInfoInUserMeta #
Generates a hash based on the user ID and stores related approval information in the user meta.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$user_id | int | n/a | The user ID for which the hash is generated. |
$team_id | int | n/a | The team ID related to the user. |
$captain_id | int | n/a | The captain ID associated with the user. |
Examples:
LevCharity\Helpers\Helper::generateHashAndSaveInfoInUserMeta(1, 10, 5);
formatAmount #
Formats an amount into a human-readable form with an appropriate suffix (K for thousands, M for millions). Default is two decimal places.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$amount | float | n/a | The amount to format. |
$decimals | int | 2 | The number of decimals to display. |
Examples:
LevCharity\Helpers\Helper::formatAmount(1234567);
formatAmountWithCommas #
Formats an amount with commas separating the thousands.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$amount | float | n/a | The amount to format. |
Examples:
LevCharity\Helpers\Helper::formatAmountWithCommas(1234567);
dateTimeToUTC #
Converts a given datetime to UTC format, considering the timezone offset from cookies.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$dateTime | string | n/a | The datetime to convert. |
$format | string | ‘Y-m-d H:i:s’ | The format for the resulting UTC datetime. |
Examples:
LevCharity\Helpers\Helper::dateTimeToUTC('2025-01-15 10:00:00');
UTCToLocalTime #
Converts a UTC datetime to local time based on the user’s timezone offset from cookies.
Returns: string|false|int
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$date_time_utc | int|string | ‘now’ | The UTC datetime to convert. |
$format | string|false | ‘Y-m-d H:i:s’ | The format for the local datetime or timestamp. |
Examples:
LevCharity\Helpers\Helper::UTCToLocalTime('2025-01-15 10:00:00');
utcTimeNow #
Returns the current UTC timestamp.
Returns: false|int
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
None | None | n/a | No properties. |
Examples:
LevCharity\Helpers\Helper::utcTimeNow();
allowedCurrencies #
Returns a list of allowed currencies, optionally excluding the shop’s default currency.
Returns: array
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$withoutShopCurrency | bool | true | Whether to exclude the shop’s default currency from the result. |
Examples:
LevCharity\Helpers\Helper::allowedCurrencies();
getP2PGoalAmountAndCurrencyByName #
Returns the goal amount and currency for a given name and currency, or an empty object if no match is found.
Returns: object|null
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$name | string | n/a | The name of the goal to match. |
$currency | string | n/a | The currency to retrieve the amount in. |
Examples:
LevCharity\Helpers\Helper::getP2PGoalAmountAndCurrencyByName('goalName', 'USD');
getLocalizedUrl #
Returns the localized URL for the provided URL based on the current language.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$url | string | n/a | The URL to localize. |
Examples:
LevCharity\Helpers\Helper::getLocalizedUrl('http://example.com');
getCurrencyCodeFromLocale #
Returns the currency code for the given locale.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$locale | string | n/a | The locale for which to get the currency code. |
Examples:
LevCharity\Helpers\Helper::getCurrencyCodeFromLocale('en_US');
calculateProductPriceForCart #
Calculates the price for a product in the cart, adjusting based on predefined or custom amounts, currency, and payment options.
Returns: void
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$cart_item | array | n/a | The cart item array. |
$cart_object | array | n/a | The cart object (optional). |
$return_price | bool | false | Whether to return the calculated price. |
Examples:
LevCharity\Helpers\Helper::calculateProductPriceForCart($cart_item, $cart_object, $return_price);
checkUserEmail #
Checks if the user’s email domain is allowed (either ‘leverage.it’ or ‘levcharity.com’).
Returns: bool
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$user_id | int | n/a | The user ID to check. |
Examples:
LevCharity\Helpers\Helper::checkUserEmail($user_id);
getModuleRedirectUrl #
Returns the redirect URL for the specified module, either to the cart or checkout page.
Returns: string
Visibility: public
Usage: static
Properties:
Name | Type | Default | Description |
---|---|---|---|
$module | string | n/a | The module name for which to retrieve the redirect URL. |
Examples:
LevCharity\Helpers\Helper::getModuleRedirectUrl('donation');