Plugin Directory

Changeset 3431384


Ignore:
Timestamp:
01/03/2026 02:15:25 AM (2 months ago)
Author:
wpabove
Message:

new patch

Location:
abovewp-bulgarian-eurozone/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • abovewp-bulgarian-eurozone/trunk/abovewp-bulgarian-eurozone.php

    r3421026 r3431384  
    33 * Plugin Name: AboveWP Bulgarian Eurozone
    44 * Description: Adds bidirectional dual currency display (BGN ⇄ EUR) for WooCommerce as Bulgaria prepares to join the Eurozone
    5  * Version: 2.0.2
     5 * Version: 2.0.3
    66 * Author: AboveWP
    77 * Author URI: https://abovewp.com
     
    2222
    2323// Define plugin constants
    24 define('ABOVEWP_BGE_VERSION', '2.0.1');
     24define('ABOVEWP_BGE_VERSION', '2.0.3');
    2525define('ABOVEWP_BGE_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2626define('ABOVEWP_BGE_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    8181        add_action('abovewp_admin_dashboard_plugins', array($this, 'display_plugin_card'));
    8282
    83         // Only proceed if dual currency display is enabled and currency is supported (BGN or EUR)
    84         if (get_option('abovewp_bge_enabled', 'yes') !== 'yes' || !$this->is_site_currency_supported()) {
     83        // Only proceed if dual currency display is enabled and should be displayed
     84        // (BGN stores always show EUR, EUR stores only show BGN on Bulgarian locale)
     85        if (get_option('abovewp_bge_enabled', 'yes') !== 'yes' || !$this->should_display_dual_currency()) {
    8586            return;
    8687        }
     
    143144    private function is_site_currency_supported() {
    144145        return $this->is_site_currency_bgn() || $this->is_site_currency_eur();
     146    }
     147
     148    /**
     149     * Check if dual currency display should be active
     150     * For BGN stores: always show EUR (everyone should see the EUR equivalent)
     151     * For EUR stores: only show BGN on Bulgarian locale (for multilang/multicurrency compatibility)
     152     *
     153     * @return bool
     154     */
     155    private function should_display_dual_currency() {
     156        if (!$this->is_site_currency_supported()) {
     157            return false;
     158        }
     159       
     160        // For BGN stores, always show EUR equivalent
     161        if ($this->is_site_currency_bgn()) {
     162            return true;
     163        }
     164       
     165        // For EUR stores, only show BGN equivalent on Bulgarian locale
     166        if ($this->is_site_currency_eur()) {
     167            $locale = get_locale();
     168            // Check for Bulgarian locale (bg_BG or just bg)
     169            return strpos($locale, 'bg') === 0;
     170        }
     171       
     172        return false;
    145173    }
    146174
     
    661689    public function convert_eur_to_bgn($price_eur) {
    662690        // Always use the official EUR to BGN conversion rate
    663         $price_bgn = $price_eur * $this->conversion_rate;
     691        $price_bgn_raw = $price_eur * $this->conversion_rate;
    664692       
    665693        // Check if within 0.05 of a whole number
    666         $nearest_int = round($price_bgn);
    667         if (abs($price_bgn - $nearest_int) <= 0.05) {
    668             return $nearest_int;
    669         }
    670        
    671         // Otherwise round to nearest 0.10
    672         return round($price_bgn, 1);
     694        $nearest_int = round($price_bgn_raw);
     695        if (abs($price_bgn_raw - $nearest_int) <= 0.05) {
     696            $price_bgn = $nearest_int;
     697        } else {
     698            // Otherwise round to nearest 0.10
     699            $price_bgn = round($price_bgn_raw, 1);
     700        }
     701       
     702        /**
     703         * Filter the converted BGN price from EUR
     704         *
     705         * Allows developers to customize the rounding logic for EUR to BGN conversion.
     706         *
     707         * @since 2.0.3
     708         * @param float $price_bgn The rounded BGN price (after smart rounding)
     709         * @param float $price_eur The original EUR price (input)
     710         * @param float $price_bgn_raw The raw unrounded BGN price (before rounding)
     711         */
     712        return apply_filters('abovewp_bge_convert_eur_to_bgn', $price_bgn, $price_eur, $price_bgn_raw);
    673713    }
    674714
  • abovewp-bulgarian-eurozone/trunk/readme.txt

    r3421026 r3431384  
    55Tested up to: 6.8
    66Requires PHP: 7.2
    7 Stable tag: 2.0.2
     7Stable tag: 2.0.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    108108== Changelog ==
    109109
     110= 2.0.3 =
     111* NEW: Locale-aware dual currency display - BGN prices now only appear alongside EUR on Bulgarian locale (bg_BG) for better multilang/multicurrency compatibility
     112* NEW: Filter `abovewp_bge_convert_eur_to_bgn` - developers can now customize the EUR to BGN rounding logic
     113
    110114= 2.0.2 =
    111115Improved rounding on bgn currency while euro is the main one
     
    190194== Upgrade Notice ==
    191195
     196= 2.0.3 =
     197Improved multilang/multicurrency support: BGN prices now only display on Bulgarian locale when store currency is EUR. Added developer filter for custom rounding logic.
     198
    192199= 2.0.2 =
    193200Improved rounding
Note: See TracChangeset for help on using the changeset viewer.