slug) ? (string) $t->slug : ''; }, (array) $terms ); $slugs = array_filter(array_map('trim', $slugs)); } /** * Filter the computed segment/category slugs for a product. * * @param string[] $slugs * @param int $product_id */ $slugs = apply_filters('affilibee_product_segment_slugs', $slugs, $product_id); return implode(',', $slugs); } /** * Get the number of minor-unit decimals for a currency. * Defaults to 2, with common overrides (e.g., JPY=0, KWD=3). * * @param string $currency ISO 4217 currency code (e.g. 'USD', 'JPY'). */ public static function currency_decimals(string $currency): int { $currency = strtoupper($currency); // Common zero-decimal currencies $zero = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'); // Common 3-decimal currencies $three = array('BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND'); $decimals = 2; if (in_array($currency, $zero, true)) { $decimals = 0; } elseif (in_array($currency, $three, true)) { $decimals = 3; } /** * Filter the number of decimals for a currency. * * @param int $decimals * @param string $currency */ return (int) apply_filters('affilibee_currency_decimals', $decimals, $currency); } /** * Convert a major-unit amount (e.g. 10.50) to integer minor units (e.g. 1050). * * @param float|int|string $amount Major units amount from WooCommerce totals. * @param string $currency ISO 4217 currency code. */ public static function to_minor_units($amount, string $currency): int { $decimals = self::currency_decimals($currency); $factor = 10 ** $decimals; // round() prevents floating point artifacts (e.g. 1009.9999 -> 1010) return (int) round((float) $amount * $factor); } }