<?php
namespace Wpexperts\CurrencySwitcherForWoocommerce;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

class Helper {

	public static function get_all_active_payment_gateways() {
		$gateways         = WC()->payment_gateways->get_available_payment_gateways();
		$enabled_gateways = array();
		if ( $gateways ) {
			foreach ( $gateways as $gateway ) {
				if ( 'yes' == $gateway->enabled ) {
					$arr                = array();
					$arr['id']          = $gateway->id;
					$arr['title']       = $gateway->title;
					$arr['enabled']     = $gateway->enabled;
					$enabled_gateways[] = $arr;
				}
			}
		}

		return $enabled_gateways;
	}

	public static function wccs_delete_all_between( $beginning, $end, $string ) {
		$beginningPos = strpos( $string, $beginning );
		$endPos       = strpos( $string, $end );
		if ( false === $beginningPos || false === $endPos ) {
			return $string;
		}

		$textToDelete = substr( $string, $beginningPos, ( $endPos + strlen( $end ) ) - $beginningPos );

		return wccs_delete_all_between( $beginning, $end, str_replace( $textToDelete, '', $string ) ); // recursion to ensure all occurrences are replaced
	}

	public static function wccs_get_country_currency( $code ) {
		$arr = array(
			'AF' => 'AFN',
			'AL' => 'ALL',
			'DZ' => 'DZD',
			'AS' => 'USD',
			'AD' => 'EUR',
			'AO' => 'AOA',
			'AI' => 'XCD',
			'AQ' => 'XCD',
			'AG' => 'XCD',
			'AR' => 'ARS',
			'AM' => 'AMD',
			'AW' => 'AWG',
			'AU' => 'AUD',
			'AT' => 'EUR',
			'AZ' => 'AZN',
			'BS' => 'BSD',
			'BH' => 'BHD',
			'BD' => 'BDT',
			'BB' => 'BBD',
			'BY' => 'BYR',
			'BE' => 'EUR',
			'BZ' => 'BZD',
			'BJ' => 'XOF',
			'BM' => 'BMD',
			'BT' => 'BTN',
			'BO' => 'BOB',
			'BA' => 'BAM',
			'BW' => 'BWP',
			'BV' => 'NOK',
			'BR' => 'BRL',
			'IO' => 'USD',
			'BN' => 'BND',
			'BG' => 'BGN',
			'BF' => 'XOF',
			'BI' => 'BIF',
			'KH' => 'KHR',
			'CM' => 'XAF',
			'CA' => 'CAD',
			'CV' => 'CVE',
			'KY' => 'KYD',
			'CF' => 'XAF',
			'TD' => 'XAF',
			'CL' => 'CLP',
			'CN' => 'CNY',
			'HK' => 'HKD',
			'CX' => 'AUD',
			'CC' => 'AUD',
			'CO' => 'COP',
			'KM' => 'KMF',
			'CG' => 'XAF',
			'CD' => 'CDF',
			'CK' => 'NZD',
			'CR' => 'CRC',
			'HR' => 'HRK',
			'CU' => 'CUP',
			'CY' => 'EUR',
			'CZ' => 'CZK',
			'DK' => 'DKK',
			'DJ' => 'DJF',
			'DM' => 'XCD',
			'DO' => 'DOP',
			'EC' => 'ECS',
			'EG' => 'EGP',
			'SV' => 'SVC',
			'GQ' => 'XAF',
			'ER' => 'ERN',
			'EE' => 'EUR',
			'ET' => 'ETB',
			'FK' => 'FKP',
			'FO' => 'DKK',
			'FJ' => 'FJD',
			'FI' => 'EUR',
			'FR' => 'EUR',
			'GF' => 'EUR',
			'TF' => 'EUR',
			'GA' => 'XAF',
			'GM' => 'GMD',
			'GE' => 'GEL',
			'DE' => 'EUR',
			'GH' => 'GHS',
			'GI' => 'GIP',
			'GR' => 'EUR',
			'GL' => 'DKK',
			'GD' => 'XCD',
			'GP' => 'EUR',
			'GU' => 'USD',
			'GT' => 'QTQ',
			'GG' => 'GGP',
			'GN' => 'GNF',
			'GW' => 'GWP',
			'GY' => 'GYD',
			'HT' => 'HTG',
			'HM' => 'AUD',
			'HN' => 'HNL',
			'HU' => 'HUF',
			'IS' => 'ISK',
			'IN' => 'INR',
			'ID' => 'IDR',
			'IR' => 'IRR',
			'IQ' => 'IQD',
			'IE' => 'EUR',
			'IM' => 'GBP',
			'IL' => 'ILS',
			'IT' => 'EUR',
			'JM' => 'JMD',
			'JP' => 'JPY',
			'JE' => 'GBP',
			'JO' => 'JOD',
			'KZ' => 'KZT',
			'KE' => 'KES',
			'KI' => 'AUD',
			'KP' => 'KPW',
			'KR' => 'KRW',
			'KW' => 'KWD',
			'KG' => 'KGS',
			'LA' => 'LAK',
			'LV' => 'EUR',
			'LB' => 'LBP',
			'LS' => 'LSL',
			'LR' => 'LRD',
			'LY' => 'LYD',
			'LI' => 'CHF',
			'LT' => 'EUR',
			'LU' => 'EUR',
			'MK' => 'MKD',
			'MG' => 'MGF',
			'MW' => 'MWK',
			'MY' => 'MYR',
			'MV' => 'MVR',
			'ML' => 'XOF',
			'MT' => 'EUR',
			'MH' => 'USD',
			'MQ' => 'EUR',
			'MR' => 'MRO',
			'MU' => 'MUR',
			'YT' => 'EUR',
			'MX' => 'MXN',
			'FM' => 'USD',
			'MD' => 'MDL',
			'MC' => 'EUR',
			'MN' => 'MNT',
			'ME' => 'EUR',
			'MS' => 'XCD',
			'MA' => 'MAD',
			'MZ' => 'MZN',
			'MM' => 'MMK',
			'NA' => 'NAD',
			'NR' => 'AUD',
			'NP' => 'NPR',
			'NL' => 'EUR',
			'AN' => 'ANG',
			'NC' => 'XPF',
			'NZ' => 'NZD',
			'NI' => 'NIO',
			'NE' => 'XOF',
			'NG' => 'NGN',
			'NU' => 'NZD',
			'NF' => 'AUD',
			'MP' => 'USD',
			'NO' => 'NOK',
			'OM' => 'OMR',
			'PK' => 'PKR',
			'PW' => 'USD',
			'PA' => 'PAB',
			'PG' => 'PGK',
			'PY' => 'PYG',
			'PE' => 'PEN',
			'PH' => 'PHP',
			'PN' => 'NZD',
			'PL' => 'PLN',
			'PT' => 'EUR',
			'PR' => 'USD',
			'QA' => 'QAR',
			'RE' => 'EUR',
			'RO' => 'RON',
			'RU' => 'RUB',
			'RW' => 'RWF',
			'SH' => 'SHP',
			'KN' => 'XCD',
			'LC' => 'XCD',
			'PM' => 'EUR',
			'VC' => 'XCD',
			'WS' => 'WST',
			'SM' => 'EUR',
			'ST' => 'STD',
			'SA' => 'SAR',
			'SN' => 'XOF',
			'RS' => 'RSD',
			'SC' => 'SCR',
			'SL' => 'SLL',
			'SG' => 'SGD',
			'SK' => 'EUR',
			'SI' => 'EUR',
			'SB' => 'SBD',
			'SO' => 'SOS',
			'ZA' => 'ZAR',
			'GS' => 'GBP',
			'SS' => 'SSP',
			'ES' => 'EUR',
			'LK' => 'LKR',
			'SD' => 'SDG',
			'SR' => 'SRD',
			'SJ' => 'NOK',
			'SZ' => 'SZL',
			'SE' => 'SEK',
			'CH' => 'CHF',
			'SY' => 'SYP',
			'TW' => 'TWD',
			'TJ' => 'TJS',
			'TZ' => 'TZS',
			'TH' => 'THB',
			'TG' => 'XOF',
			'TK' => 'NZD',
			'TO' => 'TOP',
			'TT' => 'TTD',
			'TN' => 'TND',
			'TR' => 'TRY',
			'TM' => 'TMT',
			'TC' => 'USD',
			'TV' => 'AUD',
			'UG' => 'UGX',
			'UA' => 'UAH',
			'AE' => 'AED',
			'GB' => 'GBP',
			'US' => 'USD',
			'UM' => 'USD',
			'UY' => 'UYU',
			'UZ' => 'UZS',
			'VU' => 'VUV',
			'VE' => 'VEF',
			'VN' => 'VND',
			'VI' => 'USD',
			'WF' => 'XPF',
			'EH' => 'MAD',
			'YE' => 'YER',
			'ZM' => 'ZMW',
			'ZW' => 'ZWD',
		);

		return isset( $arr[ $code ] ) ? $arr[ $code ] : '';
	}

	public static function wccs_free_shipping_criteria() {
		if ( class_exists( 'WCCS' ) ) {

			// remove filter from plugin first
			remove_filter( 'woocommerce_package_rates', array( $GLOBALS['WCCS'], 'wccs_change_shipping_rates_cost' ), 10, 2 );

			// override shipping price
			add_filter( 'woocommerce_package_rates', 'wccs_change_free_shipping_price_criteria', 99, 2 );
			function wccs_change_free_shipping_price_criteria( $rates, $package ) {

				$coversion_rate = $GLOBALS['WCCS']->wccs_get_currency_rate();
				$decimals       = $GLOBALS['WCCS']->wccs_get_currency_decimals();

				$amount_for_free_shipping = 70.00; // set free shipping threshold
				$cart_total               = WC()->cart->subtotal;

				foreach ( $rates as $id => $rate ) {

					if ( $coversion_rate ) {

						$amount_for_free_shipping = round( ( $amount_for_free_shipping * $coversion_rate ), $decimals );

						if ( $cart_total < $amount_for_free_shipping ) {
							if ( 'free_shipping' === $rate->method_id ) {
								unset( $rates[ $id ] );
							}
						}

						if ( isset( $rates[ $id ] ) ) {
							$rates[ $id ]->cost = round( ( $rates[ $id ]->cost * $coversion_rate ), $decimals );
							// Taxes rate cost (if enabled)
							$taxes = array();
							foreach ( $rates[ $id ]->taxes as $key => $tax ) {
								if ( $tax > 0 ) { // set the new tax cost
									// set the new line tax cost in the taxes array
									$taxes[ $key ] = round( ( $tax * $coversion_rate ), $decimals );
								}
							}
							// Set the new taxes costs
							$rates[ $id ]->taxes = $taxes;
						}
					} elseif ( $cart_total < $amount_for_free_shipping ) {


						if ( 'free_shipping' === $rate->method_id ) {
							unset( $rates[ $id ] );
						}
					}
				}

				return $rates;
			}
		}
	}

	/**
	 * Get the list of all woocommerce currencies.
	 * 
	 * You can exclude the default woocommerce currency or any other currencies.
	 * 
	 * @return array
	 */
	public static function wccs_get_available_currencies( $exclude = array(), $exclude_default = true ) {
		$currencies = get_woocommerce_currencies();
		
		if ($exclude_default) {
			$default = get_woocommerce_currency();
			if ($default && isset($currencies[ $default ])) {
				unset($currencies[ $default ]);
			}
		}
			
		foreach ($exclude as $code) {
			if (isset($currencies[ $code ])) {
				unset($currencies[ $code ]);
			}
		}
		
		return $currencies;
	}

	/**
	 * Get currency label by currency code or woocommerce default currency
	 * 
	 * @return string
	 */
	public static function wccs_get_currency_label( $currency = null ) {
		$label = '';
		
		if (!$currency) {
			$currency = get_woocommerce_currency();
		}
		
		$currencies = get_woocommerce_currencies();
		
		if (isset($currencies[ $currency ])) {
			$label = $currencies[ $currency ];
		}
		/**
		 * Filter
		 * 
		 * @since 1.0.0
		 */
		return apply_filters('wccs_change_default_currency_label', $label);
	}


	/**
	 * Get all flags urls
	 * 
	 * @return array
	 */
	public static function wccs_get_all_flags() {
		$flags = array(
			'AF',
			'AX',
			'AL',
			'DZ',
			'AS',
			'AD',
			'AO',
			'AI',
			'AQ',
			'AG',
			'AR',
			'AM',
			'AN',
			'AW',
			'AU',
			'AT',
			'AZ',
			'BS',
			'BH',
			'BD',
			'BB',
			'BY',
			'BE',
			'BZ',
			'BJ',
			'BM',
			'BT',
			'BO',
			'BQ',
			'BA',
			'BW',
			'BV',
			'BR',
			'IO',
			'UM',
			'VG',
			'VI',
			'BN',
			'BG',
			'BF',
			'BI',
			'KH',
			'CM',
			'CA',
			'CV',
			'KY',
			'CF',
			'TD',
			'CL',
			'CN',
			'CX',
			'CC',
			'CO',
			'KM',
			'CG',
			'CD',
			'CK',
			'CR',
			'HR',
			'CU',
			'CW',
			'CY',
			'CZ',
			'DK',
			'DJ',
			'DM',
			'DO',
			'EC',
			'EG',
			'SV',
			'GQ',
			'ER',
			'EE',
			'ET',
			'EU',
			'FK',
			'FO',
			'FJ',
			'FI',
			'FR',
			'GF',
			'PF',
			'TF',
			'GA',
			'GM',
			'GE',
			'DE',
			'GH',
			'GI',
			'GR',
			'GL',
			'GD',
			'GP',
			'GU',
			'GT',
			'GG',
			'GN',
			'GW',
			'GY',
			'HT',
			'HM',
			'VA',
			'HN',
			'HK',
			'HU',
			'IS',
			'IN',
			'ID',
			'CI',
			'IR',
			'IQ',
			'IE',
			'IM',
			'IL',
			'IT',
			'JM',
			'JP',
			'JE',
			'JO',
			'KZ',
			'KE',
			'KI',
			'KW',
			'KG',
			'LA',
			'LV',
			'LB',
			'LS',
			'LR',
			'LY',
			'LI',
			'LT',
			'LU',
			'MO',
			'MK',
			'MG',
			'MW',
			'MY',
			'MV',
			'ML',
			'MT',
			'MH',
			'MQ',
			'MR',
			'MU',
			'YT',
			'MX',
			'FM',
			'MD',
			'MC',
			'MN',
			'ME',
			'MS',
			'MA',
			'MZ',
			'MM',
			'NA',
			'NR',
			'NP',
			'NL',
			'NC',
			'NZ',
			'NI',
			'NE',
			'NG',
			'NU',
			'NF',
			'KP',
			'MP',
			'NO',
			'OM',
			'PK',
			'PW',
			'PS',
			'PA',
			'PG',
			'PY',
			'PE',
			'PH',
			'PN',
			'PL',
			'PT',
			'PR',
			'QA',
			'XK',
			'RE',
			'RO',
			'RU',
			'RW',
			'BL',
			'SH',
			'KN',
			'LC',
			'MF',
			'PM',
			'VC',
			'WS',
			'SM',
			'ST',
			'SA',
			'SN',
			'RS',
			'SC',
			'SL',
			'SG',
			'SX',
			'SK',
			'SI',
			'SB',
			'SO',
			'ZA',
			'GS',
			'KR',
			'SS',
			'ES',
			'LK',
			'SD',
			'SR',
			'SJ',
			'SZ',
			'SE',
			'CH',
			'SY',
			'TW',
			'TJ',
			'TZ',
			'TH',
			'TL',
			'TG',
			'TK',
			'TO',
			'TT',
			'TN',
			'TR',
			'TM',
			'TC',
			'TV',
			'UG',
			'UA',
			'AE',
			'GB',
			'US',
			'UY',
			'UZ',
			'VU',
			'VE',
			'VN',
			'WF',
			'EH',
			'YE',
			'ZM',
			'ZW',
		);
		/**
		 * Filter
		 * 
		 * @since 1.0.0
		 */
		return apply_filters('wccs_flags', $flags);
	}

	/**
	 * Get_currency_countries.
	 *
	 * 158 currencies.
	 * Three-letter currency code (ISO 4217) => Two-letter countries codes (ISO 3166-1 alpha-2).
	 */
	public static function get_currency_countries( $currency_code = '' ) {
		$arr = array(
			'AFN' => array( 'AF' ),
			'ALL' => array( 'AL' ),
			'DZD' => array( 'DZ' ),
			'USD' => array( 'AS', 'IO', 'GU', 'MH', 'FM', 'MP', 'PW', 'PR', 'TC', 'US', 'UM', 'VI' ),
			'EUR' => array( 'AD', 'AT', 'BE', 'CY', 'EE', 'FI', 'FR', 'GF', 'TF', 'DE', 'GR', 'GP', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'MQ', 'YT', 'MC', 'ME', 'NL', 'PT', 'RE', 'PM', 'SM', 'SK', 'SI', 'ES', 'EU' ),
			'AOA' => array( 'AO' ),
			'XCD' => array( 'AI', 'AQ', 'AG', 'DM', 'GD', 'MS', 'KN', 'LC', 'VC' ),
			'ARS' => array( 'AR' ),
			'AMD' => array( 'AM' ),
			'AWG' => array( 'AW' ),
			'AUD' => array( 'AU', 'CX', 'CC', 'HM', 'KI', 'NR', 'NF', 'TV' ),
			'AZN' => array( 'AZ' ),
			'BSD' => array( 'BS' ),
			'BHD' => array( 'BH' ),
			'BDT' => array( 'BD' ),
			'BBD' => array( 'BB' ),
			'BYR' => array( 'BY' ),
			'BYN' => array( 'BY' ),
			'BZD' => array( 'BZ' ),
			'XOF' => array( 'BJ', 'BF', 'ML', 'NE', 'SN', 'TG' ),
			'BMD' => array( 'BM' ),
			'BTN' => array( 'BT' ),
			'BOB' => array( 'BO' ),
			'BAM' => array( 'BA' ),
			'BWP' => array( 'BW' ),
			'NOK' => array( 'BV', 'NO', 'SJ' ),
			'BRL' => array( 'BR' ),
			'BND' => array( 'BN' ),
			'BGN' => array( 'BG' ),
			'BIF' => array( 'BI' ),
			'KHR' => array( 'KH' ),
			'XAF' => array( 'CM', 'CF', 'TD', 'CG', 'GQ', 'GA' ),
			'CAD' => array( 'CA' ),
			'CVE' => array( 'CV' ),
			'KYD' => array( 'KY' ),
			'CLP' => array( 'CL' ),
			'CNY' => array( 'CN' ),
			'HKD' => array( 'HK' ),
			'COP' => array( 'CO' ),
			'KMF' => array( 'KM' ),
			'CDF' => array( 'CD' ),
			'NZD' => array( 'CK', 'NZ', 'NU', 'PN', 'TK' ),
			'CRC' => array( 'CR' ),
			'HRK' => array( 'HR' ),
			'CUP' => array( 'CU' ),
			'CZK' => array( 'CZ' ),
			'DKK' => array( 'DK', 'FO', 'GL' ),
			'DJF' => array( 'DJ' ),
			'DOP' => array( 'DO' ),
			'ECS' => array( 'EC' ),
			'EGP' => array( 'EG' ),
			'SVC' => array( 'SV' ),
			'ERN' => array( 'ER' ),
			'ETB' => array( 'ET' ),
			'FKP' => array( 'FK' ),
			'FJD' => array( 'FJ' ),
			'GMD' => array( 'GM' ),
			'GEL' => array( 'GE' ),
			'GHS' => array( 'GH' ),
			'GIP' => array( 'GI' ),
			'QTQ' => array( 'GT' ),
			'GGP' => array( 'GG' ),
			'GNF' => array( 'GN' ),
			'GWP' => array( 'GW' ),
			'GYD' => array( 'GY' ),
			'HTG' => array( 'HT' ),
			'HNL' => array( 'HN' ),
			'HUF' => array( 'HU' ),
			'ISK' => array( 'IS' ),
			'INR' => array( 'IN' ),
			'IDR' => array( 'ID' ),
			'IRR' => array( 'IR' ),
			'IQD' => array( 'IQ' ),
			'GBP' => array( 'IM', 'JE', 'GS', 'GB' ),
			'ILS' => array( 'IL' ),
			'JMD' => array( 'JM' ),
			'JPY' => array( 'JP' ),
			'JOD' => array( 'JO' ),
			'KZT' => array( 'KZ' ),
			'KES' => array( 'KE' ),
			'KPW' => array( 'KP' ),
			'KRW' => array( 'KR' ),
			'KWD' => array( 'KW' ),
			'KGS' => array( 'KG' ),
			'LAK' => array( 'LA' ),
			'LBP' => array( 'LB' ),
			'LSL' => array( 'LS' ),
			'LRD' => array( 'LR' ),
			'LYD' => array( 'LY' ),
			'CHF' => array( 'LI', 'CH' ),
			'MKD' => array( 'MK' ),
			'MGF' => array( 'MG' ),
			'MWK' => array( 'MW' ),
			'MYR' => array( 'MY' ),
			'MVR' => array( 'MV' ),
			'MRO' => array( 'MR' ),
			'MUR' => array( 'MU' ),
			'MXN' => array( 'MX' ),
			'MDL' => array( 'MD' ),
			'MNT' => array( 'MN' ),
			'MAD' => array( 'MA', 'EH' ),
			'MZN' => array( 'MZ' ),
			'MMK' => array( 'MM' ),
			'NAD' => array( 'NA' ),
			'NPR' => array( 'NP' ),
			'ANG' => array( 'AN' ),
			'XPF' => array( 'NC', 'WF' ),
			'NIO' => array( 'NI' ),
			'NGN' => array( 'NG' ),
			'OMR' => array( 'OM' ),
			'PKR' => array( 'PK' ),
			'PAB' => array( 'PA' ),
			'PGK' => array( 'PG' ),
			'PYG' => array( 'PY' ),
			'PEN' => array( 'PE' ),
			'PHP' => array( 'PH' ),
			'PLN' => array( 'PL' ),
			'QAR' => array( 'QA' ),
			'RON' => array( 'RO' ),
			'RUB' => array( 'RU' ),
			'RWF' => array( 'RW' ),
			'SHP' => array( 'SH' ),
			'WST' => array( 'WS' ),
			'STD' => array( 'ST' ),
			'SAR' => array( 'SA' ),
			'RSD' => array( 'RS' ),
			'SCR' => array( 'SC' ),
			'SLL' => array( 'SL' ),
			'SGD' => array( 'SG' ),
			'SBD' => array( 'SB' ),
			'SOS' => array( 'SO' ),
			'ZAR' => array( 'ZA' ),
			'SSP' => array( 'SS' ),
			'LKR' => array( 'LK' ),
			'SDG' => array( 'SD' ),
			'SRD' => array( 'SR' ),
			'SZL' => array( 'SZ' ),
			'SEK' => array( 'SE' ),
			'SYP' => array( 'SY' ),
			'TWD' => array( 'TW' ),
			'TJS' => array( 'TJ' ),
			'TZS' => array( 'TZ' ),
			'THB' => array( 'TH' ),
			'TOP' => array( 'TO' ),
			'TTD' => array( 'TT' ),
			'TND' => array( 'TN' ),
			'TRY' => array( 'TR' ),
			'TMT' => array( 'TM' ),
			'UGX' => array( 'UG' ),
			'UAH' => array( 'UA' ),
			'AED' => array( 'AE' ),
			'UYU' => array( 'UY' ),
			'UZS' => array( 'UZ' ),
			'VUV' => array( 'VU' ),
			'VEF' => array( 'VE' ),
			'VND' => array( 'VN' ),
			'YER' => array( 'YE' ),
			'ZMW' => array( 'ZM' ),
			'ZWD' => array( 'ZW' ),
		);
		
		if ( ! empty(trim($currency_code)) ) {
			return isset($arr[ $currency_code ]) ? $arr[ $currency_code ] : '';
		}
	}
 
	public static function wccs_get_email_body( $type, $args = array() ) {
		$message = '';
		
		switch ($type) {
			case 'currency_update':
				if (isset($args['changed']) && count($args['changed'])) {
					$message .= 'Dear admin,<br/>';
					$message .= 'This email was sent to you to let you know which currencies rates were updated.';
					$message .= '<table>';
					$message .= '<thead>';
					$message .= '<tr>';
					$message .= '<th>' . __('Currency', 'multi-currency-switcher') . '</th><th>' . __('New Rate', 'multi-currency-switcher') . '</th>';
					$message .= '</tr>';
					$message .= '</thead>';
					$message .= '<tbody>';
					
					foreach ($args['changed'] as $label => $rate) {
						$message .= '<tr>';
						$message .= '<td>' . $label . '</td><td>' . $rate . '</td>';
						$message .= '</tr>';
					}

					$message .= '</tbody>';
					$message .= '<table>';
				}
				break;
		}
		
		return $message;
	}

	public static function get_mulltisite_or_site_option( $key, $value = false ) {
		if ( is_multisite() ) {
			$wccs_option = get_site_option($key, $value);
		} else {
			$wccs_option = get_option($key, $value);
		}

		return $wccs_option;
	}
}
