Changeset 3335964
- Timestamp:
- 07/29/2025 12:43:56 PM (7 months ago)
- Location:
- abovewp-bulgarian-eurozone/trunk
- Files:
-
- 2 edited
-
abovewp-bulgarian-eurozone.php (modified) (57 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
abovewp-bulgarian-eurozone/trunk/abovewp-bulgarian-eurozone.php
r3331621 r3335964 3 3 * Plugin Name: AboveWP Bulgarian Eurozone 4 4 * Description: Adds dual currency display (BGN and EUR) for WooCommerce as Bulgaria prepares to join the Eurozone 5 * Version: 1.2. 25 * Version: 1.2.3 6 6 * Author: AboveWP 7 7 * Author URI: https://abovewp.com … … 22 22 23 23 // Define plugin constants 24 define('ABOVEWP_BGE_VERSION', '1.2. 2');24 define('ABOVEWP_BGE_VERSION', '1.2.3'); 25 25 define('ABOVEWP_BGE_PLUGIN_DIR', plugin_dir_path(__FILE__)); 26 26 define('ABOVEWP_BGE_PLUGIN_URL', plugin_dir_url(__FILE__)); … … 71 71 add_action('admin_menu', array($this, 'add_admin_menu')); 72 72 add_action('admin_init', array($this, 'register_settings')); 73 73 74 74 // Remove WordPress admin notices on our admin pages 75 75 add_action('admin_head', array($this, 'remove_admin_notices_on_plugin_pages')); 76 76 77 77 // Enqueue admin styles 78 78 add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles')); … … 114 114 return false; 115 115 } 116 116 117 117 return get_woocommerce_currency() === 'BGN'; 118 118 } … … 201 201 add_filter('woocommerce_cart_shipping_method_full_label', array($this, 'add_eur_to_shipping_label'), 10, 2); 202 202 } 203 203 204 204 if (get_option('abovewp_bge_show_tax_labels', 'yes') === 'yes') { 205 205 add_filter('woocommerce_order_tax_totals', array($this, 'add_eur_to_order_tax_totals'), 10, 2); … … 216 216 add_filter('woocommerce_get_order_item_totals', array($this, 'add_eur_to_order_totals'), 10, 3); 217 217 } 218 218 219 219 // Enqueue JavaScript for Blocks 220 220 add_action('wp_enqueue_scripts', array($this, 'enqueue_blocks_scripts')); … … 279 279 ) 280 280 ); 281 282 283 281 282 283 284 284 // EUR label setting 285 285 register_setting( … … 293 293 ) 294 294 ); 295 295 296 296 // EUR price position setting 297 297 register_setting( … … 307 307 ) 308 308 ); 309 309 310 310 // EUR price display format setting 311 311 register_setting( … … 321 321 ) 322 322 ); 323 323 324 324 // Display location settings (checkboxes) 325 325 $display_locations = array( … … 337 337 'thank_you_page' => esc_html__('Thank you / Order received page', 'abovewp-bulgarian-eurozone') 338 338 ); 339 339 340 340 foreach ($display_locations as $key => $label) { 341 341 register_setting( … … 365 365 </div> 366 366 <h1><?php esc_html_e('Bulgarian Eurozone Settings', 'abovewp-bulgarian-eurozone'); ?></h1> 367 367 368 368 <?php if (!$this->is_site_currency_bgn()): ?> 369 369 <div class="notice notice-error"> … … 378 378 </div> 379 379 <?php endif; ?> 380 380 381 381 <form method="post" action="options.php"> 382 382 <?php settings_fields('abovewp_bge_settings'); ?> 383 383 <?php do_settings_sections('abovewp_bge_settings'); ?> 384 384 385 385 <h2><?php esc_html_e('General Settings', 'abovewp-bulgarian-eurozone'); ?></h2> 386 386 <table class="form-table"> … … 426 426 </tr> 427 427 </table> 428 428 429 429 <?php if ($this->is_site_currency_bgn()): ?> 430 430 <h2><?php esc_html_e('Display Locations', 'abovewp-bulgarian-eurozone'); ?></h2> 431 431 <p class="description"><?php esc_html_e('Select where you want to display EUR prices:', 'abovewp-bulgarian-eurozone'); ?></p> 432 432 433 433 <table class="form-table"> 434 434 <?php … … 447 447 'thank_you_page' => esc_html__('Thank you / Order received page', 'abovewp-bulgarian-eurozone') 448 448 ); 449 449 450 450 foreach ($display_locations as $key => $label) : 451 451 ?> … … 462 462 </table> 463 463 <?php endif; ?> 464 464 465 465 <?php submit_button(null, 'primary', 'submit', true, $this->is_site_currency_bgn() ? [] : ['disabled' => 'disabled']); ?> 466 466 </form> … … 502 502 return wc_get_price_excluding_tax($product, array('qty' => $qty)); 503 503 } 504 504 505 505 case 'order': 506 506 // Use cart tax display setting for orders … … 511 511 return wc_get_price_excluding_tax($product, array('qty' => $qty)); 512 512 } 513 513 514 514 case 'shop': 515 515 default: … … 550 550 $format = get_option('abovewp_bge_eur_format', 'brackets'); 551 551 $position = get_option('abovewp_bge_eur_position', 'right'); 552 552 553 553 if ($format === 'divider') { 554 554 // Side divider format: "25лв. / 12.78 €" … … 558 558 $eur_span = '<span class="' . esc_attr($css_class) . '">(' . esc_html($eur_formatted) . ')</span>'; 559 559 } 560 560 561 561 if ($position === 'left') { 562 562 return $eur_span . ' ' . $bgn_price_html; … … 578 578 $format = get_option('abovewp_bge_eur_format', 'brackets'); 579 579 $position = get_option('abovewp_bge_eur_position', 'right'); 580 580 581 581 if ($format === 'divider') { 582 582 // Side divider format: "25лв. / 12.78 €" … … 586 586 $eur_span = '<span class="' . esc_attr($css_class) . '">(' . esc_html($eur_formatted) . ')</span>'; 587 587 } 588 588 589 589 if ($position === 'left') { 590 590 return $eur_span . ' ' . $existing_value; … … 605 605 return $price_html; 606 606 } 607 607 608 608 // Skip variable products as they're handled by display_dual_price_variable 609 609 if ($product->is_type('variable')) { … … 611 611 } 612 612 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 613 630 // Use WooCommerce function that respects tax display settings 614 631 $price_bgn = wc_get_price_to_display($product); 615 632 $price_eur = $this->convert_bgn_to_eur($price_bgn); 616 633 617 634 return $this->format_dual_price($price_html, $price_eur); 618 635 } … … 628 645 // Get min and max prices using tax-aware functions 629 646 $tax_display_mode = get_option('woocommerce_tax_display_shop'); 630 647 631 648 if ('incl' === $tax_display_mode) { 632 649 $min_price_bgn = $product->get_variation_price('min', true); // true = include taxes … … 636 653 $max_price_bgn = $product->get_variation_price('max', false); 637 654 } 638 655 639 656 // Convert to EUR 640 657 $min_price_eur = $this->convert_bgn_to_eur($min_price_bgn); 641 658 $max_price_eur = $this->convert_bgn_to_eur($max_price_bgn); 642 659 643 660 // If prices are the same, show single price, otherwise show range 644 661 if ($min_price_bgn === $max_price_bgn) { … … 649 666 $eur_label = esc_html($this->get_eur_label()); 650 667 $eur_range = $min_price_formatted . ' - ' . $max_price_formatted . ' ' . $eur_label; 651 668 652 669 $format = get_option('abovewp_bge_eur_format', 'brackets'); 653 670 $position = get_option('abovewp_bge_eur_position', 'right'); 654 671 655 672 if ($format === 'divider') { 656 673 // Side divider format: "25лв. / 12.78 €" … … 660 677 $eur_span = '<span class="eur-price">(' . $eur_range . ')</span>'; 661 678 } 662 679 663 680 if ($position === 'left') { 664 681 return $eur_span . ' ' . $price_html; … … 684 701 $product_price = wc_get_price_excluding_tax($cart_item['data']); 685 702 } 686 703 687 704 $price_eur = $this->convert_bgn_to_eur($product_price); 688 705 689 706 return $this->format_dual_price($price_html, $price_eur); 690 707 } … … 700 717 public function display_dual_price_cart_subtotal($subtotal, $cart_item, $cart_item_key) { 701 718 $quantity = $cart_item['quantity']; 702 719 703 720 // Use WooCommerce cart's tax-aware subtotal calculation 704 721 if (WC()->cart->display_prices_including_tax()) { … … 707 724 $subtotal_bgn = wc_get_price_excluding_tax($cart_item['data'], array('qty' => $quantity)); 708 725 } 709 726 710 727 $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn); 711 728 712 729 return $this->format_dual_price($subtotal, $subtotal_eur); 713 730 } … … 723 740 $cart_total_bgn = WC()->cart->get_total(false); 724 741 $cart_total_eur = $this->convert_bgn_to_eur($cart_total_bgn); 725 742 726 743 return $this->format_dual_price($total, $cart_total_eur); 727 744 } … … 738 755 return $fee_html; 739 756 } 740 757 741 758 $fee_amount_bgn = $fee->amount; 742 759 if ($fee_amount_bgn > 0) { … … 744 761 $fee_html = $this->add_eur_to_value($fee_html, $fee_amount_eur); 745 762 } 746 763 747 764 return $fee_html; 748 765 } … … 763 780 $cart_subtotal_bgn = $cart->get_subtotal(); 764 781 } 765 782 766 783 $cart_subtotal_eur = $this->convert_bgn_to_eur($cart_subtotal_bgn); 767 784 768 785 return $this->format_dual_price($subtotal, $cart_subtotal_eur); 769 786 } … … 780 797 // Create a new array for the modified rows 781 798 $modified_rows = array(); 782 799 783 800 foreach ($total_rows as $key => $row) { 784 801 if ($key === 'cart_subtotal') { … … 791 808 $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn); 792 809 $row['value'] = $this->add_eur_to_value($row['value'], $subtotal_eur); 793 } 810 } 794 811 elseif ($key === 'shipping') { 795 812 // Add EUR to shipping based on tax display mode … … 831 848 $row['value'] = $this->add_eur_to_value($row['value'], $total_eur); 832 849 } 833 850 834 851 $modified_rows[$key] = $row; 835 852 } 836 853 837 854 return $modified_rows; 838 855 } … … 846 863 public function add_eur_column_to_orders_table($columns) { 847 864 $new_columns = array(); 848 865 849 866 foreach ($columns as $key => $column) { 850 867 $new_columns[$key] = $column; 851 868 852 869 if ($key === 'order-total') { 853 870 // Translators: %s is the currency label (EUR) … … 855 872 } 856 873 } 857 874 858 875 return $new_columns; 859 876 } … … 867 884 $order_total_bgn = $order->get_total(); 868 885 $order_total_eur = $this->convert_bgn_to_eur($order_total_bgn); 869 886 870 887 echo esc_html($this->format_eur_price($order_total_eur)); 871 888 } … … 881 898 public function add_eur_price_to_api($response, $post, $request) { 882 899 $data = $response->get_data(); 883 900 884 901 if (isset($data['price']) && isset($data['id'])) { 885 902 $product = wc_get_product($data['id']); … … 892 909 } 893 910 } 894 911 895 912 return $response; 896 913 } … … 909 926 $label = $this->add_eur_to_value($label, $shipping_cost_eur); 910 927 } 911 928 912 929 return $label; 913 930 } … … 926 943 return $html; 927 944 } 928 945 929 946 $quantity = $cart_item['quantity']; 930 947 931 948 // Use WooCommerce cart's tax-aware calculation for mini cart 932 949 if (WC()->cart->display_prices_including_tax()) { … … 935 952 $subtotal_bgn = wc_get_price_excluding_tax($cart_item['data'], array('qty' => $quantity)); 936 953 } 937 954 938 955 $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn); 939 956 940 957 return $this->add_eur_to_value($html, $subtotal_eur); 941 958 } … … 955 972 return $discount; 956 973 } 957 974 958 975 $discount_eur = $this->convert_bgn_to_eur($discount); 959 976 $GLOBALS['dual_currency_coupon_eur'] = $discount_eur; 960 977 961 978 return $discount; 962 979 } … … 972 989 // Get the discount amount for this coupon 973 990 $discount_amount = WC()->cart->get_coupon_discount_amount($coupon->get_code(), WC()->cart->display_prices_including_tax()); 974 991 975 992 if ($discount_amount > 0) { 976 993 $discount_eur = $this->convert_bgn_to_eur($discount_amount); … … 978 995 return $this->add_eur_to_value($coupon_html, $discount_eur); 979 996 } 980 997 981 998 return $coupon_html; 982 999 } … … 1002 1019 public function remove_admin_notices_on_plugin_pages() { 1003 1020 $screen = get_current_screen(); 1004 1021 1005 1022 // Only remove notices on our plugin pages 1006 1023 if (isset($screen->id) && ( 1007 strpos($screen->id, 'abovewp-bulgarian-eurozone') !== false || 1024 strpos($screen->id, 'abovewp-bulgarian-eurozone') !== false || 1008 1025 strpos($screen->id, 'toplevel_page_abovewp') !== false 1009 1026 )) { … … 1011 1028 remove_all_actions('admin_notices'); 1012 1029 remove_all_actions('all_admin_notices'); 1013 1030 1014 1031 // Add our custom CSS to hide any notices that might get through 1015 1032 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; 1018 1035 } 1019 1036 </style>'; … … 1036 1053 ABOVEWP_BGE_VERSION 1037 1054 ); 1038 1055 1039 1056 // Add JavaScript 1040 1057 wp_enqueue_script( … … 1045 1062 true 1046 1063 ); 1047 1064 1048 1065 // Localize script with data 1049 1066 wp_localize_script('abovewp-bulgarian-eurozone-blocks', 'abovewpBGE', array( … … 1066 1083 // Get the tax display setting for orders 1067 1084 $tax_display = get_option('woocommerce_tax_display_cart'); 1068 1085 1069 1086 if ('incl' === $tax_display) { 1070 1087 // Include item tax in the subtotal for EUR conversion … … 1073 1090 $subtotal_bgn = $item->get_total(); 1074 1091 } 1075 1092 1076 1093 $subtotal_eur = $this->convert_bgn_to_eur($subtotal_bgn); 1077 1094 1078 1095 return $this->add_eur_to_value($subtotal, $subtotal_eur); 1079 1096 } … … 1090 1107 $formatted_amount = null; 1091 1108 $amount = 0; 1092 1109 1093 1110 if (is_array($tax)) { 1094 1111 $formatted_amount = isset($tax['formatted_amount']) ? $tax['formatted_amount'] : null; … … 1098 1115 $amount = isset($tax->amount) ? $tax->amount : 0; 1099 1116 } 1100 1117 1101 1118 if ($formatted_amount && strpos($formatted_amount, $this->get_eur_label()) === false && $amount > 0) { 1102 1119 $tax_amount_eur = $this->convert_bgn_to_eur($amount); 1103 1120 $formatted_amount_with_eur = $this->add_eur_to_value($formatted_amount, $tax_amount_eur); 1104 1121 1105 1122 if (is_array($tax)) { 1106 1123 $tax['formatted_amount'] = $formatted_amount_with_eur; -
abovewp-bulgarian-eurozone/trunk/readme.txt
r3331614 r3335964 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.2 7 Stable tag: 1.2. 27 Stable tag: 1.2.3 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 78 78 == Changelog == 79 79 80 = 1.2.3 = 81 * Now shows old price on sale products in euro as well. 82 80 83 = 1.2.2 = 81 84 * Compatibility issue fixes for promo codes. … … 131 134 == Upgrade Notice == 132 135 136 = 1.2.3 = 137 Now shows old price on sale products in euro as well. 138 133 139 = 1.2.2 = 134 140 Compatibility issue fixes for promo codes.
Note: See TracChangeset
for help on using the changeset viewer.