Plugin Directory

Changeset 3335964


Ignore:
Timestamp:
07/29/2025 12:43:56 PM (7 months ago)
Author:
wpabove
Message:

1.2.3

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

Legend:

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

    r3331621 r3335964  
    33 * Plugin Name: AboveWP Bulgarian Eurozone
    44 * Description: Adds dual currency display (BGN and EUR) for WooCommerce as Bulgaria prepares to join the Eurozone
    5  * Version: 1.2.2
     5 * Version: 1.2.3
    66 * Author: AboveWP
    77 * Author URI: https://abovewp.com
     
    2222
    2323// Define plugin constants
    24 define('ABOVEWP_BGE_VERSION', '1.2.2');
     24define('ABOVEWP_BGE_VERSION', '1.2.3');
    2525define('ABOVEWP_BGE_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2626define('ABOVEWP_BGE_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    7171        add_action('admin_menu', array($this, 'add_admin_menu'));
    7272        add_action('admin_init', array($this, 'register_settings'));
    73 
     73       
    7474        // Remove WordPress admin notices on our admin pages
    7575        add_action('admin_head', array($this, 'remove_admin_notices_on_plugin_pages'));
    76 
     76       
    7777        // Enqueue admin styles
    7878        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
     
    114114            return false;
    115115        }
    116 
     116       
    117117        return get_woocommerce_currency() === 'BGN';
    118118    }
     
    201201            add_filter('woocommerce_cart_shipping_method_full_label', array($this, 'add_eur_to_shipping_label'), 10, 2);
    202202        }
    203 
     203       
    204204        if (get_option('abovewp_bge_show_tax_labels', 'yes') === 'yes') {
    205205            add_filter('woocommerce_order_tax_totals', array($this, 'add_eur_to_order_tax_totals'), 10, 2);
     
    216216            add_filter('woocommerce_get_order_item_totals', array($this, 'add_eur_to_order_totals'), 10, 3);
    217217        }
    218 
     218       
    219219        // Enqueue JavaScript for Blocks
    220220        add_action('wp_enqueue_scripts', array($this, 'enqueue_blocks_scripts'));
     
    279279            )
    280280        );
    281 
    282 
    283 
     281       
     282
     283       
    284284        // EUR label setting
    285285        register_setting(
     
    293293            )
    294294        );
    295 
     295       
    296296        // EUR price position setting
    297297        register_setting(
     
    307307            )
    308308        );
    309 
     309       
    310310        // EUR price display format setting
    311311        register_setting(
     
    321321            )
    322322        );
    323 
     323       
    324324        // Display location settings (checkboxes)
    325325        $display_locations = array(
     
    337337            'thank_you_page' => esc_html__('Thank you / Order received page', 'abovewp-bulgarian-eurozone')
    338338        );
    339 
     339       
    340340        foreach ($display_locations as $key => $label) {
    341341            register_setting(
     
    365365            </div>
    366366            <h1><?php esc_html_e('Bulgarian Eurozone Settings', 'abovewp-bulgarian-eurozone'); ?></h1>
    367 
     367           
    368368            <?php if (!$this->is_site_currency_bgn()): ?>
    369369            <div class="notice notice-error">
     
    378378            </div>
    379379            <?php endif; ?>
    380 
     380           
    381381            <form method="post" action="options.php">
    382382                <?php settings_fields('abovewp_bge_settings'); ?>
    383383                <?php do_settings_sections('abovewp_bge_settings'); ?>
    384 
     384               
    385385                <h2><?php esc_html_e('General Settings', 'abovewp-bulgarian-eurozone'); ?></h2>
    386386                <table class="form-table">
     
    426426                    </tr>
    427427                </table>
    428 
     428               
    429429                <?php if ($this->is_site_currency_bgn()): ?>
    430430                <h2><?php esc_html_e('Display Locations', 'abovewp-bulgarian-eurozone'); ?></h2>
    431431                <p class="description"><?php esc_html_e('Select where you want to display EUR prices:', 'abovewp-bulgarian-eurozone'); ?></p>
    432 
     432               
    433433                <table class="form-table">
    434434                    <?php
     
    447447                        'thank_you_page' => esc_html__('Thank you / Order received page', 'abovewp-bulgarian-eurozone')
    448448                    );
    449 
     449                   
    450450                    foreach ($display_locations as $key => $label) :
    451451                    ?>
     
    462462                </table>
    463463                <?php endif; ?>
    464 
     464               
    465465                <?php submit_button(null, 'primary', 'submit', true, $this->is_site_currency_bgn() ? [] : ['disabled' => 'disabled']); ?>
    466466            </form>
     
    502502                    return wc_get_price_excluding_tax($product, array('qty' => $qty));
    503503                }
    504 
     504               
    505505            case 'order':
    506506                // Use cart tax display setting for orders
     
    511511                    return wc_get_price_excluding_tax($product, array('qty' => $qty));
    512512                }
    513 
     513               
    514514            case 'shop':
    515515            default:
     
    550550        $format = get_option('abovewp_bge_eur_format', 'brackets');
    551551        $position = get_option('abovewp_bge_eur_position', 'right');
    552 
     552       
    553553        if ($format === 'divider') {
    554554            // Side divider format: "25лв. / 12.78 €"
     
    558558            $eur_span = '<span class="' . esc_attr($css_class) . '">(' . esc_html($eur_formatted) . ')</span>';
    559559        }
    560 
     560       
    561561        if ($position === 'left') {
    562562            return $eur_span . ' ' . $bgn_price_html;
     
    578578        $format = get_option('abovewp_bge_eur_format', 'brackets');
    579579        $position = get_option('abovewp_bge_eur_position', 'right');
    580 
     580       
    581581        if ($format === 'divider') {
    582582            // Side divider format: "25лв. / 12.78 €"
     
    586586            $eur_span = '<span class="' . esc_attr($css_class) . '">(' . esc_html($eur_formatted) . ')</span>';
    587587        }
    588 
     588       
    589589        if ($position === 'left') {
    590590            return $eur_span . ' ' . $existing_value;
     
    605605            return $price_html;
    606606        }
    607 
     607       
    608608        // Skip variable products as they're handled by display_dual_price_variable
    609609        if ($product->is_type('variable')) {
     
    611611        }
    612612
     613        if ($product->is_on_sale()) {
     614            $regular_price_bgn = wc_get_price_to_display($product, array('price' => $product->get_regular_price()));
     615            $sale_price_bgn = wc_get_price_to_display($product, array('price' => $product->get_sale_price()));
     616           
     617            // Convert to EUR
     618            $regular_price_eur = $this->convert_bgn_to_eur($regular_price_bgn);
     619            $sale_price_eur = $this->convert_bgn_to_eur($sale_price_bgn);
     620           
     621            $regular_price_dual = $this->format_dual_price(wc_price($regular_price_bgn), $regular_price_eur);
     622            $sale_price_dual = $this->format_dual_price(wc_price($sale_price_bgn), $sale_price_eur);
     623           
     624            // Use WooCommerce's built-in sale price formatting
     625            $price_html = wc_format_sale_price($regular_price_dual, $sale_price_dual);
     626           
     627            return $price_html;
     628        }
     629       
    613630        // Use WooCommerce function that respects tax display settings
    614631        $price_bgn = wc_get_price_to_display($product);
    615632        $price_eur = $this->convert_bgn_to_eur($price_bgn);
    616 
     633       
    617634        return $this->format_dual_price($price_html, $price_eur);
    618635    }
     
    628645        // Get min and max prices using tax-aware functions
    629646        $tax_display_mode = get_option('woocommerce_tax_display_shop');
    630 
     647       
    631648        if ('incl' === $tax_display_mode) {
    632649            $min_price_bgn = $product->get_variation_price('min', true); // true = include taxes
     
    636653            $max_price_bgn = $product->get_variation_price('max', false);
    637654        }
    638 
     655       
    639656        // Convert to EUR
    640657        $min_price_eur = $this->convert_bgn_to_eur($min_price_bgn);
    641658        $max_price_eur = $this->convert_bgn_to_eur($max_price_bgn);
    642 
     659       
    643660        // If prices are the same, show single price, otherwise show range
    644661        if ($min_price_bgn === $max_price_bgn) {
     
    649666            $eur_label = esc_html($this->get_eur_label());
    650667            $eur_range = $min_price_formatted . ' - ' . $max_price_formatted . ' ' . $eur_label;
    651 
     668           
    652669            $format = get_option('abovewp_bge_eur_format', 'brackets');
    653670            $position = get_option('abovewp_bge_eur_position', 'right');
    654 
     671           
    655672            if ($format === 'divider') {
    656673                // Side divider format: "25лв. / 12.78 €"
     
    660677                $eur_span = '<span class="eur-price">(' . $eur_range . ')</span>';
    661678            }
    662 
     679           
    663680            if ($position === 'left') {
    664681                return $eur_span . ' ' . $price_html;
     
    684701            $product_price = wc_get_price_excluding_tax($cart_item['data']);
    685702        }
    686 
     703       
    687704        $price_eur = $this->convert_bgn_to_eur($product_price);
    688 
     705       
    689706        return $this->format_dual_price($price_html, $price_eur);
    690707    }
     
    700717    public function display_dual_price_cart_subtotal($subtotal, $cart_item, $cart_item_key) {
    701718        $quantity = $cart_item['quantity'];
    702 
     719       
    703720        // Use WooCommerce cart's tax-aware subtotal calculation
    704721        if (WC()->cart->display_prices_including_tax()) {
     
    707724            $subtotal_bgn = wc_get_price_excluding_tax($cart_item['data'], array('qty' => $quantity));
    708725        }
    709 
     726       
    710727        $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn);
    711 
     728       
    712729        return $this->format_dual_price($subtotal, $subtotal_eur);
    713730    }
     
    723740        $cart_total_bgn = WC()->cart->get_total(false);
    724741        $cart_total_eur = $this->convert_bgn_to_eur($cart_total_bgn);
    725 
     742       
    726743        return $this->format_dual_price($total, $cart_total_eur);
    727744    }
     
    738755            return $fee_html;
    739756        }
    740 
     757       
    741758        $fee_amount_bgn = $fee->amount;
    742759        if ($fee_amount_bgn > 0) {
     
    744761            $fee_html = $this->add_eur_to_value($fee_html, $fee_amount_eur);
    745762        }
    746 
     763       
    747764        return $fee_html;
    748765    }
     
    763780            $cart_subtotal_bgn = $cart->get_subtotal();
    764781        }
    765 
     782       
    766783        $cart_subtotal_eur = $this->convert_bgn_to_eur($cart_subtotal_bgn);
    767 
     784       
    768785        return $this->format_dual_price($subtotal, $cart_subtotal_eur);
    769786    }
     
    780797        // Create a new array for the modified rows
    781798        $modified_rows = array();
    782 
     799       
    783800        foreach ($total_rows as $key => $row) {
    784801            if ($key === 'cart_subtotal') {
     
    791808                $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn);
    792809                $row['value'] = $this->add_eur_to_value($row['value'], $subtotal_eur);
    793             }
     810            } 
    794811            elseif ($key === 'shipping') {
    795812                // Add EUR to shipping based on tax display mode
     
    831848                $row['value'] = $this->add_eur_to_value($row['value'], $total_eur);
    832849            }
    833 
     850           
    834851            $modified_rows[$key] = $row;
    835852        }
    836 
     853       
    837854        return $modified_rows;
    838855    }
     
    846863    public function add_eur_column_to_orders_table($columns) {
    847864        $new_columns = array();
    848 
     865       
    849866        foreach ($columns as $key => $column) {
    850867            $new_columns[$key] = $column;
    851 
     868           
    852869            if ($key === 'order-total') {
    853870                // Translators: %s is the currency label (EUR)
     
    855872            }
    856873        }
    857 
     874       
    858875        return $new_columns;
    859876    }
     
    867884        $order_total_bgn = $order->get_total();
    868885        $order_total_eur = $this->convert_bgn_to_eur($order_total_bgn);
    869 
     886       
    870887        echo esc_html($this->format_eur_price($order_total_eur));
    871888    }
     
    881898    public function add_eur_price_to_api($response, $post, $request) {
    882899        $data = $response->get_data();
    883 
     900       
    884901        if (isset($data['price']) && isset($data['id'])) {
    885902            $product = wc_get_product($data['id']);
     
    892909            }
    893910        }
    894 
     911       
    895912        return $response;
    896913    }
     
    909926            $label = $this->add_eur_to_value($label, $shipping_cost_eur);
    910927        }
    911 
     928       
    912929        return $label;
    913930    }
     
    926943            return $html;
    927944        }
    928 
     945       
    929946        $quantity = $cart_item['quantity'];
    930 
     947       
    931948        // Use WooCommerce cart's tax-aware calculation for mini cart
    932949        if (WC()->cart->display_prices_including_tax()) {
     
    935952            $subtotal_bgn = wc_get_price_excluding_tax($cart_item['data'], array('qty' => $quantity));
    936953        }
    937 
     954       
    938955        $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn);
    939 
     956       
    940957        return $this->add_eur_to_value($html, $subtotal_eur);
    941958    }
     
    955972            return $discount;
    956973        }
    957 
     974       
    958975        $discount_eur = $this->convert_bgn_to_eur($discount);
    959976        $GLOBALS['dual_currency_coupon_eur'] = $discount_eur;
    960 
     977       
    961978        return $discount;
    962979    }
     
    972989        // Get the discount amount for this coupon
    973990        $discount_amount = WC()->cart->get_coupon_discount_amount($coupon->get_code(), WC()->cart->display_prices_including_tax());
    974 
     991       
    975992        if ($discount_amount > 0) {
    976993            $discount_eur = $this->convert_bgn_to_eur($discount_amount);
     
    978995            return $this->add_eur_to_value($coupon_html, $discount_eur);
    979996        }
    980 
     997       
    981998        return $coupon_html;
    982999    }
     
    10021019    public function remove_admin_notices_on_plugin_pages() {
    10031020        $screen = get_current_screen();
    1004 
     1021       
    10051022        // Only remove notices on our plugin pages
    10061023        if (isset($screen->id) && (
    1007             strpos($screen->id, 'abovewp-bulgarian-eurozone') !== false ||
     1024            strpos($screen->id, 'abovewp-bulgarian-eurozone') !== false || 
    10081025            strpos($screen->id, 'toplevel_page_abovewp') !== false
    10091026        )) {
     
    10111028            remove_all_actions('admin_notices');
    10121029            remove_all_actions('all_admin_notices');
    1013 
     1030           
    10141031            // Add our custom CSS to hide any notices that might get through
    10151032            echo '<style>
    1016                 .notice, .updated, .update-nag, .error, .warning, .info {
    1017                     display: none !important;
     1033                .notice, .updated, .update-nag, .error, .warning, .info { 
     1034                    display: none !important; 
    10181035                }
    10191036            </style>';
     
    10361053            ABOVEWP_BGE_VERSION
    10371054        );
    1038 
     1055       
    10391056        // Add JavaScript
    10401057        wp_enqueue_script(
     
    10451062            true
    10461063        );
    1047 
     1064       
    10481065        // Localize script with data
    10491066        wp_localize_script('abovewp-bulgarian-eurozone-blocks', 'abovewpBGE', array(
     
    10661083        // Get the tax display setting for orders
    10671084        $tax_display = get_option('woocommerce_tax_display_cart');
    1068 
     1085       
    10691086        if ('incl' === $tax_display) {
    10701087            // Include item tax in the subtotal for EUR conversion
     
    10731090            $subtotal_bgn = $item->get_total();
    10741091        }
    1075 
     1092       
    10761093        $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn);
    1077 
     1094       
    10781095        return $this->add_eur_to_value($subtotal, $subtotal_eur);
    10791096    }
     
    10901107            $formatted_amount = null;
    10911108            $amount = 0;
    1092 
     1109           
    10931110            if (is_array($tax)) {
    10941111                $formatted_amount = isset($tax['formatted_amount']) ? $tax['formatted_amount'] : null;
     
    10981115                $amount = isset($tax->amount) ? $tax->amount : 0;
    10991116            }
    1100 
     1117           
    11011118            if ($formatted_amount && strpos($formatted_amount, $this->get_eur_label()) === false && $amount > 0) {
    11021119                $tax_amount_eur = $this->convert_bgn_to_eur($amount);
    11031120                $formatted_amount_with_eur = $this->add_eur_to_value($formatted_amount, $tax_amount_eur);
    1104 
     1121               
    11051122                if (is_array($tax)) {
    11061123                    $tax['formatted_amount'] = $formatted_amount_with_eur;
  • abovewp-bulgarian-eurozone/trunk/readme.txt

    r3331614 r3335964  
    55Tested up to: 6.8
    66Requires PHP: 7.2
    7 Stable tag: 1.2.2
     7Stable tag: 1.2.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7878== Changelog ==
    7979
     80= 1.2.3 =
     81* Now shows old price on sale products in euro as well.
     82
    8083= 1.2.2 =
    8184* Compatibility issue fixes for promo codes.
     
    131134== Upgrade Notice ==
    132135
     136= 1.2.3 =
     137Now shows old price on sale products in euro as well.
     138
    133139= 1.2.2 =
    134140Compatibility issue fixes for promo codes.
Note: See TracChangeset for help on using the changeset viewer.