Advertisement
businessdad

WooCommerce Currency Switcher - Skip product conversion

Nov 10th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. /**
  2.  * Dummy method to suppress the "unsupported product" warning. This method
  3.  * leaves the product untouched, without performing any conversion.
  4.  *
  5.  * @param WC_Product product A product instance.
  6.  * @param string currency The target currency.
  7.  * @return WC_Product
  8.  * @author Aelia <support@aelia.co>
  9.  * @link https://aelia.co
  10.  */
  11. function aelia_skip_product_conversion($product, $currency) {
  12.   return $product;
  13. }
  14.  
  15. /**
  16.  * Replace the conversion callback with a custom one for specific product types.
  17.  *
  18.  * Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_aelia
  19.  *
  20.  * @param callable convert_callback A callback function, or method.
  21.  * @param WC_Product product A product.
  22.  * @return callable A callback function, or method.
  23.  * @author Aelia <support@aelia.co>
  24.  * @link https://aelia.co
  25.  */
  26. add_filter('wc_aelia_currencyswitcher_product_convert_callback', function($convert_callback, $product) {
  27.   // Skip conversion for products with type "accommodation-booking"
  28.   if($product->product_type === 'accommodation-booking') {
  29.     $convert_callback = 'aelia_skip_product_conversion';
  30.   }
  31.   return $convert_callback;
  32. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement