Last active
January 23, 2026 06:08
-
-
Save xlplugins/f619cc72e4ea68c69340f5e6ff2c70a1 to your computer and use it in GitHub Desktop.
FKCART Bulgarian Eurozone Integration — Dual Currency Display for Cart Items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FKCART_Bulgarian_Eurozone_Integration { | |
| private $instance = null; | |
| public function __construct() { | |
| // Hook into FunnelKit cart initialization | |
| add_filter( 'fkcart_enable_item_link', [ $this, 'add_item_meta' ] ); | |
| // Hook into FunnelKit checkout button total display | |
| // This filter is used in cart-cta.php line 54 to display the cart total | |
| add_filter( 'fkcart_checkout_button_total', [ $this, 'format_cart_total' ], 999, 1 ); | |
| add_filter( 'fkcart_subtotal_row', [ $this, 'format_subtotal_total' ], 999, 1 ); | |
| // Hook into coupon discount display | |
| // FunnelKit uses woocommerce_cart_totals_coupon_html filter (front.php line 643) | |
| // AboveWP already hooks into this, but we ensure it works in FunnelKit context | |
| add_filter( 'woocommerce_cart_totals_coupon_html', [ $this, 'format_coupon_discount' ], 99999, 2 ); | |
| } | |
| /** | |
| * Initialize cart item subtotal formatting | |
| * Called when FunnelKit cart is enabled | |
| */ | |
| public function add_item_meta( $status ) { | |
| // Hook into WooCommerce cart item subtotal filter | |
| // This is the same filter WooCommerce cart uses, ensuring consistency | |
| add_filter( 'woocommerce_cart_item_subtotal', array( $this, 'cart_loaded' ), 99999, 3 ); | |
| return $status; | |
| } | |
| /** | |
| * Format cart item subtotal with dual currency | |
| * Uses the same method as WooCommerce cart for consistency | |
| * | |
| * @param string $price Formatted price HTML | |
| * @param array $cart_item Cart item data | |
| * @param string $cart_item_key Cart item key | |
| * @return string Formatted price with BGN in brackets | |
| */ | |
| public function cart_loaded($price, $cart_item, $cart_item_key ) { | |
| if (class_exists('AboveWP_Bulgarian_Eurozone')) { | |
| // Get the global instance if it exists | |
| global $abovewp_bge; | |
| if (isset($abovewp_bge) && is_object($abovewp_bge) && method_exists($abovewp_bge, 'display_dual_price_cart_subtotal')) { | |
| // Call the method directly to apply dual currency formatting | |
| // This is the same method used in WooCommerce cart | |
| $price = $abovewp_bge->display_dual_price_cart_subtotal($price, $cart_item, $cart_item_key); | |
| } | |
| } | |
| return $price; | |
| } | |
| /** | |
| * Format cart total with dual currency | |
| * Called when FunnelKit displays the checkout button total | |
| * | |
| * @param string $total_html Formatted total HTML from WC()->cart->get_total() | |
| * @return string Formatted total with BGN in brackets | |
| */ | |
| public function format_cart_total( $total_html ) { | |
| if (class_exists('AboveWP_Bulgarian_Eurozone')) { | |
| global $abovewp_bge; | |
| if (isset($abovewp_bge) && is_object($abovewp_bge) && method_exists($abovewp_bge, 'display_dual_price_cart_total')) { | |
| // Use the AboveWP method to format cart total with dual currency | |
| // This is the same method used in WooCommerce cart totals | |
| $total_html = $abovewp_bge->display_dual_price_cart_total($total_html); | |
| } | |
| } | |
| return $total_html; | |
| } | |
| /** | |
| * Format cart subtotal row with dual currency | |
| * Hooked into fkcart_subtotal_row filter | |
| * | |
| * @param string $subtotal Formatted subtotal HTML from get_subtotal_row() | |
| * @param object $front Front instance object (optional) | |
| * @return string Formatted subtotal with BGN in brackets | |
| */ | |
| public function format_subtotal_total($subtotal, $front = null){ | |
| if (class_exists('AboveWP_Bulgarian_Eurozone')) { | |
| global $abovewp_bge; | |
| if (isset($abovewp_bge) && is_object($abovewp_bge) && method_exists($abovewp_bge, 'display_dual_price_cart_subtotal_total')) { | |
| // Get the cart object and compound value | |
| $compound = false; | |
| $cart = WC()->cart; | |
| // Check if cart exists | |
| if (!is_null($cart)) { | |
| // Use the AboveWP method to format cart subtotal with dual currency | |
| // This method requires: subtotal HTML, compound (bool), and cart object | |
| $subtotal = $abovewp_bge->display_dual_price_cart_subtotal_total($subtotal, $compound, $cart); | |
| } | |
| } | |
| } | |
| return $subtotal; | |
| } | |
| /** | |
| * Format coupon discount with dual currency | |
| * Ensures coupon discounts show BGN in brackets like WooCommerce cart | |
| * | |
| * @param string $coupon_html Formatted coupon discount HTML | |
| * @param object $coupon WC_Coupon object | |
| * @return string Formatted coupon discount with BGN in brackets | |
| */ | |
| public function format_coupon_discount( $coupon_html, $coupon ) { | |
| if (class_exists('AboveWP_Bulgarian_Eurozone')) { | |
| global $abovewp_bge; | |
| if (isset($abovewp_bge) && is_object($abovewp_bge) && method_exists($abovewp_bge, 'display_dual_price_coupon_html')) { | |
| // Use the AboveWP method to format coupon discount with dual currency | |
| // This is the same method used in WooCommerce cart | |
| $coupon_html = $abovewp_bge->display_dual_price_coupon_html($coupon_html, $coupon); | |
| } | |
| } | |
| return $coupon_html; | |
| } | |
| } | |
| new FKCART_Bulgarian_Eurozone_Integration(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment