Advertisement
businessdad

Aelia Currency Switcher fir for WooCommerce Measurement Price Calculator multi-currency

Sep 11th, 2017 (edited)
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. /**
  2.  * Measurement Price Calculator - Fix the price calculation logic to use the
  3.  * latest product price, for multi-currency compatibility.
  4.  *
  5.  * HOW TO USE THIS CODE
  6.  * Add the code to the bottom of your theme's functions.php file, and it
  7.  * will run automatically. For more information: https://www.skyverge.com/blog/add-custom-code-to-wordpress/
  8.  *
  9.  * GPL DISCLAIMER
  10.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  11.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  12.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  13.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  14.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  15.  *
  16.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  17.  *
  18.  * @param array cart_item
  19.  * @param array values
  20.  * @return array
  21.  * @tested with Measurement Price Calculator 3.12.4
  22.  */
  23. add_filter( 'woocommerce_get_cart_item_from_session', function($cart_item, $values) {
  24.   if ( isset( $values['pricing_item_meta_data'] ) ) {
  25.     // Remove the original filter, as it would cause conflicts
  26.     remove_filter( 'woocommerce_get_cart_item_from_session', array( WC_Measurement_Price_Calculator::instance()->get_cart_instance(), 'get_cart_item_from_session' ), 1, 2 );
  27.  
  28.     // Store the cart item attributes on the item
  29.     $cart_item['pricing_item_meta_data'] = $values['pricing_item_meta_data'];
  30.     // Recalculate the item price, based on the product measurements
  31.     $cart_item['pricing_item_meta_data']['_price'] = WC_Price_Calculator_Product::calculate_price($cart_item['data'],
  32.                                                                                                   $cart_item['pricing_item_meta_data']['_measurement_needed'],
  33.                                                                                                   $cart_item['pricing_item_meta_data']['_measurement_needed_unit']);
  34.  
  35.     // Set the product price (if needed)
  36.     $cart_item = WC_Measurement_Price_Calculator::instance()->get_cart_instance()->set_product_prices( $cart_item );
  37.   }
  38.   return $cart_item;
  39. }, 0, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement