WooCommerce Ultimate Multi Currency Suite, by Dev49.net
Add provided code to functions.php and update Settings.
Calculation option “Use prices modified by other plugins” must be ON.
System option “Suppress other pricing plugins in frontend” must be OFF.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
class WDP_and_WCUMCS_compatibility { private $currency_func; public function __construct() { $this->init_hooks(); } public function init_hooks() { add_action( 'init', array( $this, 'snatch_currency_function' ), 10 ); add_filter( 'wdp_get_product_price', array( $this, 'wdp_get_product_price' ), 10, 4 ); add_filter( 'wdp_update_new_price', array( $this, 'wdp_update_new_price' ), 10, 2 ); add_filter( 'wdp_update_initial_price', array( $this, 'wdp_update_initial_price' ), 10, 2 ); add_filter( 'wdp_apply_to_wc_cart', array( $this, 'wdp_apply_to_wc_cart' ), 10, 2 ); add_filter( 'wdp_rules_amount_for_item', array( $this, 'wdp_rules_amount_for_item' ), 10, 3 ); } public function wdp_get_product_price($price, $product, $price_mode, $item_meta) { if ( ! $product->is_on_sale( 'edit' ) ) { $price = $product->get_price( '' ); } return $price; } public function snatch_currency_function() { global $wp_filter; $callbacks = $wp_filter['woocommerce_product_get_regular_price']->callbacks; if ( ! $callbacks || empty( $callbacks[9999] ) ) { return; } $callbacks = $callbacks[9999]; if ( ! count( $callbacks ) ) { return; } $callback = reset( $callbacks ); $this->currency_func = isset( $callback['function'] ) ? $callback['function'] : null; } public function wdp_update_new_price( $new_price, $wc_product ) { if ( ! $this->currency_func ) { return $new_price; } $currency_func = $this->currency_func; $rate = $wc_product->get_regular_price( '' ) !== 0 ? $currency_func( $wc_product->get_regular_price( '' ), $wc_product ) / $wc_product->get_regular_price( '' ) : 0; return (float) ( $new_price * $rate ); } public function wdp_update_initial_price( $initial_price, $wc_product ) { if ( ! $this->currency_func ) { return $initial_price; } $currency_func = $this->currency_func; return $currency_func( $initial_price, $wc_product ); } public function wdp_apply_to_wc_cart( $wdp_cart, $wc_cart ) { global $wp_filter; WDP_Frontend::remove_callbacks( $wp_filter['woocommerce_product_get_price'], array( "WooCommerce_Ultimate_Multi_Currency_Suite_Frontend|custom_item_price_final" ) ); } public function wdp_rules_amount_for_item( $wdp_rules, $item, $wc_product ) { if ( ! $this->currency_func ) { return $wdp_rules; } $currency_func = $this->currency_func; foreach ( $item->get_history() as $rule_id => $amounts ) { $wdp_rules[ $rule_id ] = $currency_func( array_sum( $amounts ), $wc_product ); } return $wdp_rules; } } new WDP_and_WCUMCS_compatibility(); |