Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Replaces regular and/or sale prices for specific product IDs, depending on the currency.
- *
- * HOW TO USE THIS CODE
- * Simply 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 float converted_price
- * @param float original_price
- * @param string from_currency
- * @param string to_currency
- * @param int price_decimals
- * @param WC_Product product
- * @param string price_type
- * @return string
- */
- add_filter('wc_aelia_cs_convert_product_price', function($converted_price, $original_price, $from_currency, $to_currency, $price_decimals, $product, $price_type) {
- // Store custom product prices
- $product_prices = array(
- // 3578 is a product ID
- 3578 => array(
- 'USD' => array(
- 'regular_price' => 349,
- //'sale_price' => 99,
- ),
- 'EUR' => array(
- 'regular_price' => 340,
- //'sale_price' => 79,
- ),
- 'GBP' => array(
- 'regular_price' => 299,
- //'sale_price' => 79,
- ),
- 'AUD' => array(
- 'regular_price' => 490,
- //'sale_price' => 79,
- ),
- ),
- );
- // If a price is set for the combination of product ID, currency and price type,
- // take it and replace the result of the conversion
- if(isset($product_prices[$product->get_id()][$to_currency][$price_type])) {
- $converted_price = $product_prices[$product->get_id()][get_woocommerce_currency()][$price_type];
- }
- return $converted_price;
- }, 10, 7);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement