File "wc-formatting-functions.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/wc-formatting-functions.php
File size: 26.61 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

use Automattic\WooCommerce\Utilities\NumberUtil;
defined('ABSPATH') || exit;
function wc_string_to_bool($string)
{
    return is_bool($string) ? $string : 'yes' === strtolower($string) || 1 === $string || 'true' === strtolower($string) || '1' === $string;
}
function wc_bool_to_string($bool)
{
    if (!is_bool($bool)) {
        $bool = wc_string_to_bool($bool);
    }
    return true === $bool ? 'yes' : 'no';
}
function wc_string_to_array($string, $delimiter = ',')
{
    return is_array($string) ? $string : array_filter(explode($delimiter, $string));
}
function wc_sanitize_taxonomy_name($taxonomy)
{
    return apply_filters('sanitize_taxonomy_name', urldecode(sanitize_title(urldecode($taxonomy))), $taxonomy);
}
function wc_sanitize_permalink($value)
{
    global $wpdb;
    $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value);
    if (is_wp_error($value)) {
        $value = '';
    }
    $value = esc_url_raw(trim($value));
    $value = str_replace('http://', '', $value);
    return untrailingslashit($value);
}
function wc_get_filename_from_url($file_url)
{
    $parts = wp_parse_url($file_url);
    if (isset($parts['path'])) {
        return basename($parts['path']);
    }
}
function wc_get_dimension($dimension, $to_unit, $from_unit = '')
{
    $to_unit = strtolower($to_unit);
    if (empty($from_unit)) {
        $from_unit = strtolower(get_option('woocommerce_dimension_unit'));
    }
    if ($from_unit !== $to_unit) {
        switch ($from_unit) {
            case 'in':
                $dimension *= 2.54;
                break;
            case 'm':
                $dimension *= 100;
                break;
            case 'mm':
                $dimension *= 0.1;
                break;
            case 'yd':
                $dimension *= 91.44;
                break;
        }
        switch ($to_unit) {
            case 'in':
                $dimension *= 0.3937;
                break;
            case 'm':
                $dimension *= 0.01;
                break;
            case 'mm':
                $dimension *= 10;
                break;
            case 'yd':
                $dimension *= 0.010936133;
                break;
        }
    }
    return $dimension < 0 ? 0 : $dimension;
}
function wc_get_weight($weight, $to_unit, $from_unit = '')
{
    $weight = (float) $weight;
    $to_unit = strtolower($to_unit);
    if (empty($from_unit)) {
        $from_unit = strtolower(get_option('woocommerce_weight_unit'));
    }
    if ($from_unit !== $to_unit) {
        switch ($from_unit) {
            case 'g':
                $weight *= 0.001;
                break;
            case 'lbs':
                $weight *= 0.453592;
                break;
            case 'oz':
                $weight *= 0.0283495;
                break;
        }
        switch ($to_unit) {
            case 'g':
                $weight *= 1000;
                break;
            case 'lbs':
                $weight *= 2.20462;
                break;
            case 'oz':
                $weight *= 35.274;
                break;
        }
    }
    return $weight < 0 ? 0 : $weight;
}
function wc_trim_zeros($price)
{
    return preg_replace('/' . preg_quote(wc_get_price_decimal_separator(), '/') . '0++$/', '', $price);
}
function wc_round_tax_total($value, $precision = null)
{
    $precision = is_null($precision) ? wc_get_price_decimals() : intval($precision);
    if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
        $rounded_tax = NumberUtil::round($value, $precision, wc_get_tax_rounding_mode());
    } elseif (2 === wc_get_tax_rounding_mode()) {
        $rounded_tax = wc_legacy_round_half_down($value, $precision);
    } else {
        $rounded_tax = NumberUtil::round($value, $precision);
    }
    return apply_filters('wc_round_tax_total', $rounded_tax, $value, $precision, WC_TAX_ROUNDING_MODE);
}
function wc_legacy_round_half_down($value, $precision)
{
    $value = wc_float_to_string($value);
    if (false !== strstr($value, '.')) {
        $value = explode('.', $value);
        if (strlen($value[1]) > $precision && substr($value[1], -1) === '5') {
            $value[1] = substr($value[1], 0, -1) . '4';
        }
        $value = implode('.', $value);
    }
    return NumberUtil::round(floatval($value), $precision);
}
function wc_format_refund_total($amount)
{
    return $amount * -1;
}
function wc_format_decimal($number, $dp = false, $trim_zeros = false)
{
    $locale = localeconv();
    $decimals = array(wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point']);
    if (!is_float($number)) {
        $number = str_replace($decimals, '.', $number);
        $number = preg_replace('/\\.(?![^.]+$)|[^0-9.-]/', '', wc_clean($number));
    }
    if (false !== $dp) {
        $dp = intval('' === $dp ? wc_get_price_decimals() : $dp);
        $number = number_format(floatval($number), $dp, '.', '');
    } elseif (is_float($number)) {
        $number = str_replace($decimals, '.', sprintf('%.' . wc_get_rounding_precision() . 'f', $number));
        $trim_zeros = true;
    }
    if ($trim_zeros && strstr($number, '.')) {
        $number = rtrim(rtrim($number, '0'), '.');
    }
    return $number;
}
function wc_float_to_string($float)
{
    if (!is_float($float)) {
        return $float;
    }
    $locale = localeconv();
    $string = strval($float);
    $string = str_replace($locale['decimal_point'], '.', $string);
    return $string;
}
function wc_format_localized_price($value)
{
    return apply_filters('woocommerce_format_localized_price', str_replace('.', wc_get_price_decimal_separator(), strval($value)), $value);
}
function wc_format_localized_decimal($value)
{
    $locale = localeconv();
    return apply_filters('woocommerce_format_localized_decimal', str_replace('.', $locale['decimal_point'], strval($value)), $value);
}
function wc_format_coupon_code($value)
{
    return apply_filters('woocommerce_coupon_code', $value);
}
function wc_sanitize_coupon_code($value)
{
    return wp_filter_kses(sanitize_post_field('post_title', $value, 0, 'db'));
}
function wc_clean($var)
{
    if (is_array($var)) {
        return array_map('wc_clean', $var);
    } else {
        return is_scalar($var) ? sanitize_text_field($var) : $var;
    }
}
function wc_check_invalid_utf8($var)
{
    if (is_array($var)) {
        return array_map('wc_check_invalid_utf8', $var);
    } else {
        return wp_check_invalid_utf8($var);
    }
}
function wc_sanitize_textarea($var)
{
    return implode("\n", array_map('wc_clean', explode("\n", $var)));
}
function wc_sanitize_tooltip($var)
{
    return htmlspecialchars(wp_kses(html_entity_decode($var), array('br' => array(), 'em' => array(), 'strong' => array(), 'small' => array(), 'span' => array(), 'ul' => array(), 'li' => array(), 'ol' => array(), 'p' => array())));
}
function wc_array_overlay($a1, $a2)
{
    foreach ($a1 as $k => $v) {
        if (!array_key_exists($k, $a2)) {
            continue;
        }
        if (is_array($v) && is_array($a2[$k])) {
            $a1[$k] = wc_array_overlay($v, $a2[$k]);
        } else {
            $a1[$k] = $a2[$k];
        }
    }
    return $a1;
}
function wc_stock_amount($amount)
{
    return apply_filters('woocommerce_stock_amount', $amount);
}
function get_woocommerce_price_format()
{
    $currency_pos = get_option('woocommerce_currency_pos');
    $format = '%1$s%2$s';
    switch ($currency_pos) {
        case 'left':
            $format = '%1$s%2$s';
            break;
        case 'right':
            $format = '%2$s%1$s';
            break;
        case 'left_space':
            $format = '%1$s&nbsp;%2$s';
            break;
        case 'right_space':
            $format = '%2$s&nbsp;%1$s';
            break;
    }
    return apply_filters('woocommerce_price_format', $format, $currency_pos);
}
function wc_get_price_thousand_separator()
{
    return stripslashes(apply_filters('wc_get_price_thousand_separator', get_option('woocommerce_price_thousand_sep')));
}
function wc_get_price_decimal_separator()
{
    $separator = apply_filters('wc_get_price_decimal_separator', get_option('woocommerce_price_decimal_sep'));
    return $separator ? stripslashes($separator) : '.';
}
function wc_get_price_decimals()
{
    return absint(apply_filters('wc_get_price_decimals', get_option('woocommerce_price_num_decimals', 2)));
}
function wc_price($price, $args = array())
{
    $args = apply_filters('wc_price_args', wp_parse_args($args, array('ex_tax_label' => false, 'currency' => '', 'decimal_separator' => wc_get_price_decimal_separator(), 'thousand_separator' => wc_get_price_thousand_separator(), 'decimals' => wc_get_price_decimals(), 'price_format' => get_woocommerce_price_format())));
    $original_price = $price;
    $price = (float) $price;
    $unformatted_price = $price;
    $negative = $price < 0;
    $price = apply_filters('raw_woocommerce_price', $negative ? $price * -1 : $price, $original_price);
    $price = apply_filters('formatted_woocommerce_price', number_format($price, $args['decimals'], $args['decimal_separator'], $args['thousand_separator']), $price, $args['decimals'], $args['decimal_separator'], $args['thousand_separator'], $original_price);
    if (apply_filters('woocommerce_price_trim_zeros', false) && $args['decimals'] > 0) {
        $price = wc_trim_zeros($price);
    }
    $formatted_price = ($negative ? '-' : '') . sprintf($args['price_format'], '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol($args['currency']) . '</span>', $price);
    $return = '<span class="woocommerce-Price-amount amount"><bdi>' . $formatted_price . '</bdi></span>';
    if ($args['ex_tax_label'] && wc_tax_enabled()) {
        $return .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
    }
    return apply_filters('wc_price', $return, $price, $args, $unformatted_price, $original_price);
}
function wc_let_to_num($size)
{
    $l = substr($size, -1);
    $ret = (int) substr($size, 0, -1);
    switch (strtoupper($l)) {
        case 'P':
            $ret *= 1024;
        case 'T':
            $ret *= 1024;
        case 'G':
            $ret *= 1024;
        case 'M':
            $ret *= 1024;
        case 'K':
            $ret *= 1024;
    }
    return $ret;
}
function wc_date_format()
{
    $date_format = get_option('date_format');
    if (empty($date_format)) {
        $date_format = 'F j, Y';
    }
    return apply_filters('woocommerce_date_format', $date_format);
}
function wc_time_format()
{
    $time_format = get_option('time_format');
    if (empty($time_format)) {
        $time_format = 'g:i a';
    }
    return apply_filters('woocommerce_time_format', $time_format);
}
function wc_string_to_timestamp($time_string, $from_timestamp = null)
{
    $original_timezone = date_default_timezone_get();
    date_default_timezone_set('UTC');
    if (null === $from_timestamp) {
        $next_timestamp = strtotime($time_string);
    } else {
        $next_timestamp = strtotime($time_string, $from_timestamp);
    }
    date_default_timezone_set($original_timezone);
    return $next_timestamp;
}
function wc_string_to_datetime($time_string)
{
    if (1 === preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(Z|((-|\\+)\\d{2}:\\d{2}))$/', $time_string, $date_bits)) {
        $offset = !empty($date_bits[7]) ? iso8601_timezone_to_offset($date_bits[7]) : wc_timezone_offset();
        $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]) - $offset;
    } else {
        $timestamp = wc_string_to_timestamp(get_gmt_from_date(gmdate('Y-m-d H:i:s', wc_string_to_timestamp($time_string))));
    }
    $datetime = new WC_DateTime("@{$timestamp}", new DateTimeZone('UTC'));
    if (get_option('timezone_string')) {
        $datetime->setTimezone(new DateTimeZone(wc_timezone_string()));
    } else {
        $datetime->set_utc_offset(wc_timezone_offset());
    }
    return $datetime;
}
function wc_timezone_string()
{
    if (function_exists('wp_timezone_string')) {
        return wp_timezone_string();
    }
    $timezone = get_option('timezone_string');
    if ($timezone) {
        return $timezone;
    }
    $utc_offset = floatval(get_option('gmt_offset', 0));
    if (!is_numeric($utc_offset) || 0.0 === $utc_offset) {
        return 'UTC';
    }
    $utc_offset = (int) ($utc_offset * 3600);
    $timezone = timezone_name_from_abbr('', $utc_offset);
    if ($timezone) {
        return $timezone;
    }
    foreach (timezone_abbreviations_list() as $abbr) {
        foreach ($abbr as $city) {
            if ((bool) date('I') === (bool) $city['dst'] && $city['timezone_id'] && intval($city['offset']) === $utc_offset) {
                return $city['timezone_id'];
            }
        }
    }
    return 'UTC';
}
function wc_timezone_offset()
{
    $timezone = get_option('timezone_string');
    if ($timezone) {
        $timezone_object = new DateTimeZone($timezone);
        return $timezone_object->getOffset(new DateTime('now'));
    } else {
        return floatval(get_option('gmt_offset', 0)) * HOUR_IN_SECONDS;
    }
}
function wc_flatten_meta_callback($value)
{
    return is_array($value) ? current($value) : $value;
}
if (!function_exists('wc_rgb_from_hex')) {
    function wc_rgb_from_hex($color)
    {
        $color = str_replace('#', '', $color);
        $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
        $rgb = array();
        $rgb['R'] = hexdec($color[0] . $color[1]);
        $rgb['G'] = hexdec($color[2] . $color[3]);
        $rgb['B'] = hexdec($color[4] . $color[5]);
        return $rgb;
    }
}
if (!function_exists('wc_hex_darker')) {
    function wc_hex_darker($color, $factor = 30)
    {
        $base = wc_rgb_from_hex($color);
        $color = '#';
        foreach ($base as $k => $v) {
            $amount = $v / 100;
            $amount = NumberUtil::round($amount * $factor);
            $new_decimal = $v - $amount;
            $new_hex_component = dechex($new_decimal);
            if (strlen($new_hex_component) < 2) {
                $new_hex_component = '0' . $new_hex_component;
            }
            $color .= $new_hex_component;
        }
        return $color;
    }
}
if (!function_exists('wc_hex_lighter')) {
    function wc_hex_lighter($color, $factor = 30)
    {
        $base = wc_rgb_from_hex($color);
        $color = '#';
        foreach ($base as $k => $v) {
            $amount = 255 - $v;
            $amount = $amount / 100;
            $amount = NumberUtil::round($amount * $factor);
            $new_decimal = $v + $amount;
            $new_hex_component = dechex($new_decimal);
            if (strlen($new_hex_component) < 2) {
                $new_hex_component = '0' . $new_hex_component;
            }
            $color .= $new_hex_component;
        }
        return $color;
    }
}
if (!function_exists('wc_hex_is_light')) {
    function wc_hex_is_light($color)
    {
        $hex = str_replace('#', '', $color);
        $c_r = hexdec(substr($hex, 0, 2));
        $c_g = hexdec(substr($hex, 2, 2));
        $c_b = hexdec(substr($hex, 4, 2));
        $brightness = ($c_r * 299 + $c_g * 587 + $c_b * 114) / 1000;
        return $brightness > 155;
    }
}
if (!function_exists('wc_light_or_dark')) {
    function wc_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF')
    {
        return wc_hex_is_light($color) ? $dark : $light;
    }
}
if (!function_exists('wc_format_hex')) {
    function wc_format_hex($hex)
    {
        $hex = trim(str_replace('#', '', $hex));
        if (strlen($hex) === 3) {
            $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
        }
        return $hex ? '#' . $hex : null;
    }
}
function wc_format_postcode($postcode, $country)
{
    $postcode = wc_normalize_postcode($postcode);
    switch ($country) {
        case 'CA':
        case 'GB':
            $postcode = substr_replace($postcode, ' ', -3, 0);
            break;
        case 'IE':
            $postcode = substr_replace($postcode, ' ', 3, 0);
            break;
        case 'BR':
        case 'PL':
            $postcode = substr_replace($postcode, '-', -3, 0);
            break;
        case 'JP':
            $postcode = substr_replace($postcode, '-', 3, 0);
            break;
        case 'PT':
            $postcode = substr_replace($postcode, '-', 4, 0);
            break;
        case 'PR':
        case 'US':
            $postcode = rtrim(substr_replace($postcode, '-', 5, 0), '-');
            break;
        case 'NL':
            $postcode = substr_replace($postcode, ' ', 4, 0);
            break;
    }
    return apply_filters('woocommerce_format_postcode', trim($postcode), $country);
}
function wc_normalize_postcode($postcode)
{
    return preg_replace('/[\\s\\-]/', '', trim(wc_strtoupper($postcode)));
}
function wc_format_phone_number($phone)
{
    if (!WC_Validation::is_phone($phone)) {
        return '';
    }
    return preg_replace('/[^0-9\\+\\-\\(\\)\\s]/', '-', preg_replace('/[\\x00-\\x1F\\x7F-\\xFF]/', '', $phone));
}
function wc_sanitize_phone_number($phone)
{
    return preg_replace('/[^\\d+]/', '', $phone);
}
function wc_strtoupper($string)
{
    return function_exists('mb_strtoupper') ? mb_strtoupper($string) : strtoupper($string);
}
function wc_strtolower($string)
{
    return function_exists('mb_strtolower') ? mb_strtolower($string) : strtolower($string);
}
function wc_trim_string($string, $chars = 200, $suffix = '...')
{
    if (strlen($string) > $chars) {
        if (function_exists('mb_substr')) {
            $string = mb_substr($string, 0, $chars - mb_strlen($suffix)) . $suffix;
        } else {
            $string = substr($string, 0, $chars - strlen($suffix)) . $suffix;
        }
    }
    return $string;
}
function wc_format_content($raw_string)
{
    return apply_filters('woocommerce_format_content', apply_filters('woocommerce_short_description', $raw_string), $raw_string);
}
function wc_format_product_short_description($content)
{
    if (class_exists('WPCom_Markdown')) {
        $markdown = WPCom_Markdown::get_instance();
        return wpautop($markdown->transform($content, array('unslash' => false)));
    }
    return $content;
}
function wc_format_option_price_separators($value, $option, $raw_value)
{
    return wp_kses_post($raw_value);
}
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_price_decimal_sep', 'wc_format_option_price_separators', 10, 3);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_price_thousand_sep', 'wc_format_option_price_separators', 10, 3);
function wc_format_option_price_num_decimals($value, $option, $raw_value)
{
    return is_null($raw_value) ? 2 : absint($raw_value);
}
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_price_num_decimals', 'wc_format_option_price_num_decimals', 10, 3);
function wc_format_option_hold_stock_minutes($value, $option, $raw_value)
{
    $value = !empty($raw_value) ? absint($raw_value) : '';
    wp_clear_scheduled_hook('woocommerce_cancel_unpaid_orders');
    if ('' !== $value) {
        $cancel_unpaid_interval = apply_filters('woocommerce_cancel_unpaid_orders_interval_minutes', absint($value));
        wp_schedule_single_event(time() + absint($cancel_unpaid_interval) * 60, 'woocommerce_cancel_unpaid_orders');
    }
    return $value;
}
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_hold_stock_minutes', 'wc_format_option_hold_stock_minutes', 10, 3);
function wc_sanitize_term_text_based($term)
{
    return trim(wp_strip_all_tags(wp_unslash($term)));
}
if (!function_exists('wc_make_numeric_postcode')) {
    function wc_make_numeric_postcode($postcode)
    {
        $postcode = str_replace(array(' ', '-'), '', $postcode);
        $postcode_length = strlen($postcode);
        $letters_to_numbers = array_merge(array(0), range('A', 'Z'));
        $letters_to_numbers = array_flip($letters_to_numbers);
        $numeric_postcode = '';
        for ($i = 0; $i < $postcode_length; $i++) {
            if (is_numeric($postcode[$i])) {
                $numeric_postcode .= str_pad($postcode[$i], 2, '0', STR_PAD_LEFT);
            } elseif (isset($letters_to_numbers[$postcode[$i]])) {
                $numeric_postcode .= str_pad($letters_to_numbers[$postcode[$i]], 2, '0', STR_PAD_LEFT);
            } else {
                $numeric_postcode .= '00';
            }
        }
        return $numeric_postcode;
    }
}
function wc_format_stock_for_display($product)
{
    $display = __('In stock', 'woocommerce');
    $stock_amount = $product->get_stock_quantity();
    switch (get_option('woocommerce_stock_format')) {
        case 'low_amount':
            if ($stock_amount <= wc_get_low_stock_amount($product)) {
                $display = sprintf(__('Only %s left in stock', 'woocommerce'), wc_format_stock_quantity_for_display($stock_amount, $product));
            }
            break;
        case '':
            $display = sprintf(__('%s in stock', 'woocommerce'), wc_format_stock_quantity_for_display($stock_amount, $product));
            break;
    }
    if ($product->backorders_allowed() && $product->backorders_require_notification()) {
        $display .= ' ' . __('(can be backordered)', 'woocommerce');
    }
    return $display;
}
function wc_format_stock_quantity_for_display($stock_quantity, $product)
{
    return apply_filters('woocommerce_format_stock_quantity', $stock_quantity, $product);
}
function wc_format_sale_price($regular_price, $sale_price)
{
    $price = '<del aria-hidden="true">' . (is_numeric($regular_price) ? wc_price($regular_price) : $regular_price) . '</del> <ins>' . (is_numeric($sale_price) ? wc_price($sale_price) : $sale_price) . '</ins>';
    return apply_filters('woocommerce_format_sale_price', $price, $regular_price, $sale_price);
}
function wc_format_price_range($from, $to)
{
    $price = sprintf(_x('%1$s &ndash; %2$s', 'Price range: from-to', 'woocommerce'), is_numeric($from) ? wc_price($from) : $from, is_numeric($to) ? wc_price($to) : $to);
    return apply_filters('woocommerce_format_price_range', $price, $from, $to);
}
function wc_format_weight($weight)
{
    $weight_string = wc_format_localized_decimal($weight);
    if (!empty($weight_string)) {
        $weight_string .= ' ' . get_option('woocommerce_weight_unit');
    } else {
        $weight_string = __('N/A', 'woocommerce');
    }
    return apply_filters('woocommerce_format_weight', $weight_string, $weight);
}
function wc_format_dimensions($dimensions)
{
    $dimension_string = implode(' &times; ', array_filter(array_map('wc_format_localized_decimal', $dimensions)));
    if (!empty($dimension_string)) {
        $dimension_string .= ' ' . get_option('woocommerce_dimension_unit');
    } else {
        $dimension_string = __('N/A', 'woocommerce');
    }
    return apply_filters('woocommerce_format_dimensions', $dimension_string, $dimensions);
}
function wc_format_datetime($date, $format = '')
{
    if (!$format) {
        $format = wc_date_format();
    }
    if (!is_a($date, 'WC_DateTime')) {
        return '';
    }
    return $date->date_i18n($format);
}
function wc_do_oembeds($content)
{
    global $wp_embed;
    $content = $wp_embed->autoembed($content);
    return $content;
}
function wc_get_string_before_colon($string)
{
    return trim(current(explode(':', (string) $string)));
}
function wc_array_merge_recursive_numeric()
{
    $arrays = func_get_args();
    if (1 === count($arrays)) {
        return $arrays[0];
    }
    foreach ($arrays as $key => $array) {
        if (!is_array($array)) {
            unset($arrays[$key]);
        }
    }
    $final = array_shift($arrays);
    foreach ($arrays as $b) {
        foreach ($final as $key => $value) {
            if (!isset($b[$key])) {
                $final[$key] = $value;
            } else {
                if (is_numeric($value) && is_numeric($b[$key])) {
                    $final[$key] = $value + $b[$key];
                } elseif (is_array($value) && is_array($b[$key])) {
                    $final[$key] = wc_array_merge_recursive_numeric($value, $b[$key]);
                } else {
                    $final[$key] = $b[$key];
                }
            }
        }
        foreach ($b as $key => $value) {
            if (!isset($final[$key])) {
                $final[$key] = $value;
            }
        }
    }
    return $final;
}
function wc_implode_html_attributes($raw_attributes)
{
    $attributes = array();
    foreach ($raw_attributes as $name => $value) {
        $attributes[] = esc_attr($name) . '="' . esc_attr($value) . '"';
    }
    return implode(' ', $attributes);
}
function wc_esc_json($json, $html = false)
{
    return _wp_specialchars($json, $html ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8', true);
}
function wc_parse_relative_date_option($raw_value)
{
    $periods = array('days' => __('Day(s)', 'woocommerce'), 'weeks' => __('Week(s)', 'woocommerce'), 'months' => __('Month(s)', 'woocommerce'), 'years' => __('Year(s)', 'woocommerce'));
    $value = wp_parse_args((array) $raw_value, array('number' => '', 'unit' => 'days'));
    $value['number'] = !empty($value['number']) ? absint($value['number']) : '';
    if (!in_array($value['unit'], array_keys($periods), true)) {
        $value['unit'] = 'days';
    }
    return $value;
}
function wc_sanitize_endpoint_slug($raw_value)
{
    return sanitize_title($raw_value);
}
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_checkout_pay_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_checkout_order_received_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_add_payment_method_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_delete_payment_method_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_set_default_payment_method_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_orders_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_view_order_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_downloads_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_edit_account_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_edit_address_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_payment_methods_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_myaccount_lost_password_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);
add_filter('woocommerce_admin_settings_sanitize_option_woocommerce_logout_endpoint', 'wc_sanitize_endpoint_slug', 10, 1);