Aelia Currency Switcher fir for WooCommerce Measurement Price Calculator multi-currency
businessdad |
PRO |
02/16/23 12:04:25 AM UTC (Edited) |
0 ⭐ |
1606 👁️ |
Never ⏰ |
[woocommerce, aelia currency switcher]
/**
* Measurement Price Calculator - Fix the price calculation logic to use the
* latest product price, for multi-currency compatibility.
*
* HOW TO USE THIS CODE
* Add the code to the bottom of your theme's functions.php file, and it
* will run automatically. For more information: https://www.skyverge.com/blog/add-custom-code-to-wordpress/
*
* GPL DISCLAIMER
* Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
* Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
* without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
* merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
* is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
*
* Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
*
* @param array cart_item
* @param array values
* @return array
* @tested with Measurement Price Calculator 3.12.4
*/
add_filter( 'woocommerce_get_cart_item_from_session', function($cart_item, $values) {
if ( isset( $values['pricing_item_meta_data'] ) ) {
// Remove the original filter, as it would cause conflicts
remove_filter( 'woocommerce_get_cart_item_from_session', array( WC_Measurement_Price_Calculator::instance()->get_cart_instance(), 'get_cart_item_from_session' ), 1, 2 );
// Store the cart item attributes on the item
$cart_item['pricing_item_meta_data'] = $values['pricing_item_meta_data'];
// Recalculate the item price, based on the product measurements
$cart_item['pricing_item_meta_data']['_price'] = WC_Price_Calculator_Product::calculate_price($cart_item['data'],
$cart_item['pricing_item_meta_data']['_measurement_needed'],
$cart_item['pricing_item_meta_data']['_measurement_needed_unit']);
// Set the product price (if needed)
$cart_item = WC_Measurement_Price_Calculator::instance()->get_cart_instance()->set_product_prices( $cart_item );
}
return $cart_item;
}, 0, 2 );
Comments